Mat*_*sne 5 java android http-post youtube-api
我有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.
有谁知道如何实现这一目标?
您无法发出http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?v=2在请求正文中包含 10 个不同 URL 的批量请求。
您需要请求http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?v=2&max-results=110 次,每次请求一次USERNAME。
或者,如果您有某种服务器端进程有兴趣了解新视频何时上传到给定频道,则可以使用PubSubHubbub或SUP来更有效地处理该情况。因为你的问题被标记为android我假设你关心做这个客户端,不过。