1

I am running the YouTubeSample given on the google developers website. I have no errors in the code and my imports appear to be fine. But when I run the project I get the aforementioned error.

I have done some searches but to be honest I have been unable to work out what the problem is. I have already tried importing an external jar guava but it didn't help.

Any help is appreciated. Here is the full class

package com.pengilleys.googlesamples;
import java.io.IOException;
import java.util.List;

import com.google.api.client.googleapis.GoogleHeaders;
import com.google.api.client.googleapis.json.JsonCParser;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.client.util.Key;

public class YouTubeSample {

 public static class VideoFeed {
@Key List<Video> items;
}

public static class Video {
@Key String title;
@Key String description;
@Key Player player;
}

public static class Player {
@Key("default") String defaultUrl;
}

public static class YouTubeUrl extends GenericUrl {
@Key final String alt = "jsonc";
@Key String author;
@Key("max-results") Integer maxResults;

YouTubeUrl(String url) {
  super(url);
}
}

public static void main(String[] args) throws IOException {
// set up the HTTP request factory
HttpTransport transport = new NetHttpTransport();
final JsonFactory jsonFactory = new JacksonFactory();
HttpRequestFactory factory = transport.createRequestFactory(new    HttpRequestInitializer() {

  @Override
  public void initialize(HttpRequest request) {
    // set the parser
    JsonCParser parser = new JsonCParser();
    parser.jsonFactory = jsonFactory;
    request.addParser(parser);
    // set up the Google headers
    GoogleHeaders headers = new GoogleHeaders();
    headers.setApplicationName("Google-YouTubeSample/1.0");
    headers.gdataVersion = "2";
    request.headers = headers;
  }
});
// build the YouTube URL
YouTubeUrl url = new YouTubeUrl("https://gdata.youtube.com/feeds/api/videos");
url.author = "searchstories";
url.maxResults = 2;
// build the HTTP GET request
HttpRequest request = factory.buildGetRequest(url);
// execute the request and the parse video feed
VideoFeed feed = request.execute().parseAs(VideoFeed.class);
for (Video video : feed.items) {
  System.out.println();
  System.out.println("Video title: " + video.title);
  System.out.println("Description: " + video.description);
  System.out.println("Play URL: " + video.player.defaultUrl);
}

} }

Stephen
  • 762
  • 1
  • 12
  • 32

2 Answers2

7

The setup documentation gives a list of dependencies:

Depending on the application you are building, you may also need these dependencies:

In this case, it looks like it's Guava which is missing. I don't know what you mean about "exporting" Guava, but if you include the Guava r09 jar file in the classpath when you're running the code, it should be fine.

Community
  • 1
  • 1
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
2

what's the extra ); for above the // build the YouTube URL and did you mean to close main on that line?

knobcreekman
  • 403
  • 2
  • 4
  • 10