如何获得YouTube的视频用户 [英] How to get the youtube videos by user

查看:152
本文介绍了如何获得YouTube的视频用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示在列表视图中某YouTube频道的视频,并允许用户选择自己的视频观看之一。是否有任何的JSON数据是可用于此?

I want to display a certain youtube channel's videos in list view, and allow the user to select one of their videos to watch. Is there Any Json Data is Available for this.?

修改

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地震= json.getJSONArray(饲料);

i have permissions and the url working in tab , i am getting nullpointer error @JSONArray earthquakes = json.getJSONArray("feed");

推荐答案

您会打下面的网址,与所涉及的用户更换用户名:

You would hit the URL below, replacing USERNAME with the user in question:

http://gdata.youtube。 COM /供稿/ API /用户/用户名/上传V = 2及?ALT = jsonc

您可以在这里测试出呼叫

You can test out the calls here.

修改

如果您正在寻找NationalGeographic,网址打是:

If you are looking for NationalGeographic, the URL to hit would be:

http://gdata.youtube.com/feeds/api/users/NationalGeographic/uploads?v=2&alt=jsonc

您会发现视频网址是这样的:

You would find the video url like this:

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语句code不再赘述。

Try/catch code omitted for brevity.

这篇关于如何获得YouTube的视频用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆