Youtube 如何使用google api java客户端库检索喜爱的视频?

Youtube 如何使用google api java客户端库检索喜爱的视频?,youtube,google-api,gdata-api,gdata,google-api-java-client,Youtube,Google Api,Gdata Api,Gdata,Google Api Java Client,我正在尝试检索youtube用户最喜欢的视频。这只是一个微调。我主要想做的是打印用户最喜欢的视频列表(特别是打印标题、更新、描述等)。我确实设法得到了这个列表——但问题是所有内容(标题、描述等)都是空的!这种情况只发生在收藏夹中——我用搜索和查看次数最多的查询对其进行了测试,结果很有效。这种奇怪的行为只适用于收藏夹。。。这是我的密码: private void run() throws IOException { YouTubeClient client = new YouTu

我正在尝试检索youtube用户最喜欢的视频。这只是一个微调。我主要想做的是打印用户最喜欢的视频列表(特别是打印标题、更新、描述等)。我确实设法得到了这个列表——但问题是所有内容(标题、描述等)都是空的!这种情况只发生在收藏夹中——我用搜索和查看次数最多的查询对其进行了测试,结果很有效。这种奇怪的行为只适用于收藏夹。。。这是我的密码:

private  void run() throws IOException {
        YouTubeClient client = new YouTubeClient();
        showVideos(client);
      }

    private VideoFeed showVideos(YouTubeClient client) throws IOException {

        TextView textView = (TextView) findViewById(R.id.textView);
        View.header(textView, "Get Videos");
        YouTubeUrl url = YouTubeUrl.forVideosFeed();
        // execute GData request for the feed
        VideoFeed feed = client.executeGetVideoFeed(url);
        View.display(textView, feed);
        return feed;
      }

public class YouTubeUrl extends GoogleUrl {

  /** Whether to pretty print HTTP requests and responses. */
  private static final boolean PRETTY_PRINT = true;

  static final String ROOT_URL = "https://gdata.youtube.com/feeds/api";



  YouTubeUrl(String encodedUrl) {
    super(encodedUrl);
    this.alt = "jsonc";
    this.prettyprint = PRETTY_PRINT;
  }

  private static YouTubeUrl root() {
    return new YouTubeUrl(ROOT_URL);
  }

  public static YouTubeUrl forVideosFeed() {
    YouTubeUrl result = root();

    result.getPathParts().add("users"); //the URL is http://gdata.youtube.com/feeds/api/users/username/favorites?v=2
    result.getPathParts().add("liorash1"); //some user name
    result.getPathParts().add("favorites");

    return result;
  }
}

public class YouTubeClient {

  private final JsonFactory jsonFactory = new JacksonFactory();

  private final HttpTransport transport = new NetHttpTransport();

  private final HttpRequestFactory requestFactory;

  public YouTubeClient() {
    final JsonCParser parser = new JsonCParser(jsonFactory);
    requestFactory = transport.createRequestFactory(new HttpRequestInitializer() {

      @Override
      public void initialize(HttpRequest request) {
        // headers
        GoogleHeaders headers = new GoogleHeaders();
        headers.setApplicationName("Google-YouTubeSample/1.0");
        headers.gdataVersion = "2";
        request.setHeaders(headers);
        request.addParser(parser);
      }
    });
  }

  public VideoFeed executeGetVideoFeed(YouTubeUrl url) throws IOException {
    return executeGetFeed(url, VideoFeed.class);
  }

  private <F extends Feed<? extends Item>> F executeGetFeed(YouTubeUrl url, Class<F> feedClass)
      throws IOException {
    HttpRequest request = requestFactory.buildGetRequest(url);
    return request.execute().parseAs(feedClass);
  }
}

public class Item {

  @Key
  String title;

  @Key
  DateTime updated;
}

public class Video extends Item {

  @Key
  String description;

  @Key
  List<String> tags = new ArrayList<String>();

  @Key
  Player player;
}

一些更新:

经过一些测试,我发现我可以得到我测试过的所有提要(包括用户的上传),除了收藏夹提要。最有可能的问题是JsonCParser:

return request.execute().parseAs(feedClass);
return request.execute().parseAs(feedClass);