How to get the youtube videos by user

梦想与她 提交于 2020-01-13 06:27:07

问题


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.?

EDIT

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());
    }

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


回答1:


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

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

You can test out the calls here.

Edit

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 omitted for brevity.




回答2:


You can use Youtube APIs to get this data

http://code.google.com/apis/youtube/2.0/developers_guide_protocol_audience.html

Refer to the Searching Channels section

http://code.google.com/apis/youtube/2.0/developers_guide_protocol_channel_search.html



来源:https://stackoverflow.com/questions/8967711/how-to-get-the-youtube-videos-by-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!