Reputation: 115
I have used the following jars on my classpath for retrieving list of my subscriptions using YouTube API:
gdata-client-1.0.jar gdata-core-1.0.jar gdata-media-1.0.jar gdata-youtube-2.0.jar guava-14.0-rc1.jar mail.jar
the code is as follows:
import com.google.gdata.client.*;
import com.google.gdata.client.youtube.*;
import com.google.gdata.data.*;
import com.google.gdata.data.geo.impl.*;
import com.google.gdata.data.media.*;
import com.google.gdata.data.media.mediarss.*;
import com.google.gdata.data.youtube.*;
import com.google.gdata.data.extensions.*;
import com.google.gdata.util.*;
import java.io.IOException;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
public class YouTubeExample {
public static void main (String args[]) throws MalformedURLException, IOException, ServiceException{
String developer_key = "CSCSCSCSCSCScSCXXXXX-XXXXX_-XXXX";
YouTubeService service = new YouTubeService(developer_key);
//Retrieving video subscriptions
String feedUrl =
"http://gdata.youtube.com/feeds/api/users/GoogleDevelopers/subscriptions";
SubscriptionFeed feed = service.getFeed(new URL(feedUrl), SubscriptionFeed.class);
for(SubscriptionEntry entry : feed.getEntries()) {
System.out.println("Title: " + entry.getTitle().getPlainText());
System.out.println("Feed Link: " + entry.getFeedUrl());
}
}
}
But on running this , i get an error as follows:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet; at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399) at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableXmlTypes(AltFormat.java:387) at com.google.gdata.wireformats.AltFormat.(AltFormat.java:49) at com.google.gdata.client.Service.(Service.java:535) at YouTubeExample.main(YouTubeExample.java:21)
if i replace guava-14.0-rc1.jar with guava-10.0.1.jar (older version as per some suggestion) in the classpath i still get error like this:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.gdata.data.ExtensionProfile.declareAdditionalNamespace(Lcom/google/gdata/util/common/xml/XmlWriter$Namespace;)V at com.google.gdata.data.youtube.CommentEntry.declareExtensions(CommentEntry.java:92) at com.google.gdata.data.ExtensionProfile.addDeclarations(ExtensionProfile.java:71) at com.google.gdata.data.BaseFeed.declareExtensions(BaseFeed.java:229) at com.google.gdata.data.ExtensionProfile.addDeclarations(ExtensionProfile.java:71) at com.google.gdata.client.youtube.YouTubeService.(YouTubeService.java:140) at com.google.gdata.client.youtube.YouTubeService.(YouTubeService.java:103) at YouTubeExample.main(YouTubeExample.java:21)
I have tried including activation.jar, servlet-api.jar but no luck! I have also tried older versions such as guava 0.7 jar but no luck. Please help!
Upvotes: 1
Views: 420
Reputation: 35467
Don't import all that.
It seems that your project relies on both recent and old APIs. You shouldn't. So just check exactly what this page says.
When using Maven, to run your code, I need only the following:
<dependencies>
<dependency>
<groupId>com.google.gdata</groupId>
<artifactId>core</artifactId>
<version>1.47.1</version>
</dependency>
</dependencies>
The Maven is interesting as we can see all the hidden dependencies, and we can manage them manually to have a proper installation with all the recent versions of the libraries.
The full tree includes the following:
core: 1.47.1
guava: 13.0.1
google-oauth-client-jetty: 1.11.0-beta
google-oauth-client-java6: 1.11.0-beta
google-auth-client: 1.11.0-beta
google-http-client: 1.11.0-beta
jsr305: 1.3.9 (omitted for conflict with 1.3.7)
guava: 11.0.1 (omitted for conflict with 13.0.1)
httpclient: 4.0.3
httpcore: 4.0.1
commons-logging: 1.1.1
commons-codec: 1.3
xpp3: 1.1.4
jsr305: 1.3.9 (omitted for conflict with 1.3.7)
guava: 11.0.1 (omitted for conflict with 13.0.1)
jetty: 6.1.26
jetty-util: 6.1.26
servlet-api: 2.5-20081211
jsr305: 1.3.7
mail: 1.4
activation: 1.1
This tree shows us that it's safe to use guava 13.0.1 and that you don't really need all the other APIs you tried to include, so simply ignore them.
If you're not using Maven, use simply the projects here: https://code.google.com/p/gdata-java-client/downloads/list
Upvotes: 2