我想在 ListView 中显示某个 YouTube channel 的视频,并允许用户选择他们的视频之一进行观看。是否有任何可用的 Json 数据。?
编辑
JSONObject json = JSONfunctions.getJSONfromURL("http://gdata.youtube.com/feeds/api/videos?
author=NationalGeographic&v=2&alt=json");
try{
JSONArray earthquakes = json.getJSONArray("feed");
for(int i=0;i<earthquakes.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = earthquakes.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("name", "Earthquake name:" + e.getString("eqid"));
map.put("magnitude", "Magnitude: " + e.getString("magnitude"));
mylist.add(map);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
我有权限并且 url 在选项卡中工作,我收到空指针错误 @JSONArray earthquakes = json.getJSONArray("feed");
最佳答案
您将点击下面的 URL,将 USERNAME 替换为相关用户:
http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?v=2&alt=jsonc
您可以测试调用 here .
编辑
如果您正在寻找 NationalGeographic,要点击的 URL 将是:
http://gdata.youtube.com/feeds/api/users/NationalGeographic/uploads?v=2&alt=jsonc
您会找到这样的视频网址:
JSONObject json = JSONfunctions.getJSONfromURL("http://gdata.youtube.com/feeds/api/users/NationalGeographic/uploads?v=2&alt=jsonc");
final JSONObject data = json.getJSONObject("data");
final JSONArray array = data.getJSONArray("items");
for (int i = 0; i < array.length(); i++) {
final JSONObject item = array.getJSONObject(i);
final JSONObject player = item.getJSONObject("player");
final String url = player.getString("default"));
// The url is that of the video to be played
}
为简洁起见省略了 Try/catch 代码。
关于android - 如何按用户获取 youtube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8967711/