我有10个youtube频道,我喜欢并希望获得每个频道的最新视频信息.现在我正在进行10个不同的调用,如下所示:
http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?v=2&alt=jsonc&start-index=1&max-results=1
Run Code Online (Sandbox Code Playgroud)
我想通过使用批处理请求将这10个调用替换为单个调用.
我试过这个:
String xml = "<feed xmlns='http://www.w3.org/2005/Atom' xmlns:batch='http://schemas.google.com/gdata/batch'>" +
" <batch:operation type='query'/>" +
" <entry>" +
" <id>http://gdata.youtube.com/feeds/api/videos/VIDEO_ID_1</id>" +
" </entry>" +
" <entry>" +
" <id>http://gdata.youtube.com/feeds/api/videos/VIDEO_ID_2</id>" +
" </entry>" +
...
" <entry>" +
" <id>http://gdata.youtube.com/feeds/api/videos/VIDEO_ID_10</id>" +
" </entry>" +
"</feed>";
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("https://gdata.youtube.com/feeds/api/videos/batch?v=2");
StringEntity se = new StringEntity(xml);
se.setContentType("text/xml");
httpPost.setEntity(se);
HttpResponse response = httpClient.execute(httpPost);
Run Code Online (Sandbox Code Playgroud)
我在HTTPResponse对象中获得了一个包含有用数据的XML.
但如果我想获得10个最新视频信息,我将不会知道videoId.
有谁知道如何实现这一目标?