【问题标题】:How to get the youtube videos by user如何按用户获取 youtube 视频
【发布时间】:2012-01-23 05:55:45
【问题描述】:

我想在列表视图中显示某个 youtube 频道的视频,并允许用户选择其中一个视频进行观看。是否有任何可用的 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 在 tab 中工作,我收到 nullpointer 错误 @JSONArray 地震 = json.getJSONArray("feed");

【问题讨论】:

  • 首先,您使用了错误的 URL。请参考我的回答。

标签: android video youtube


【解决方案1】:

您将点击下面的 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
}

为简洁起见省略了尝试/捕获代码。

【讨论】:

  • 获取视频的json对象是什么
  • 有没有办法使用版本 3.0 API 做到这一点?
【解决方案2】:

【讨论】:

  • 您将获得 xml 格式的响应,您可以从中提取条目列表
  • 查看编辑我的问题..我有权限并且 url 在选项卡中工作,我收到 nullpointer 错误@JSONArray 地震 = json.getJSONArray("feed");
  • @RajdeepDua - 当您可以简单地给出要点击的确切 URL 时,为什么要让他阅读冗长的文章。此外,他显然是在要求 JSON 响应。
猜你喜欢
  • 2013-03-25
  • 2022-08-17
  • 1970-01-01
  • 2013-03-16
  • 2023-03-06
  • 2013-02-06
  • 2023-03-17
  • 2011-09-26
  • 2017-04-04
相关资源
最近更新 更多