我一直在研究有关如何从 Youtube 获取数据的信息。基本上我想做的是从播放列表(例如:http ://gdata.youtube.com/feeds/api/playlists/6A40AB04892E2A1F)中获取有关视频(标题、描述和缩略图 URL)的一些信息。我能够使用此代码片段(我从另一个问题中借用)检索标题:
String featuredFeed = "http://gdata.youtube.com/feeds/api/playlists/6A40AB04892E2A1F";
url = new URL(featuredFeed);
URLConnection connection;
connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream in = httpConnection.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.parse(in);
Element docEle = dom.getDocumentElement();
NodeList nl = docEle.getElementsByTagName("entry");
// NodeList nl2 = ;
if (nl != null && nl.getLength() > 0) {
for (int i = 0; i < nl.getLength(); i++) {
Element entry = (Element) nl.item(i);
Element title = (Element) entry.getElementsByTagName(
"title").item(0);
String titleStr = title.getFirstChild().getNodeValue();
Log.i("TEST LOG", "TITLES: " + titleStr);
}
}
}
但是我不太清楚如何检索缩略图 URL。我看过标签,但我不知道如何从节点列表中调用它。谁能告诉我如何使用这种方法检索视频的缩略图 URL 和视频描述?
提前致谢。