使用json从youtube检索视频(categoryID)

时间:2013-05-17 08:23:38

标签: android json youtube-api android-youtube-api

我想从我的应用上传YouTube视频,然后查找这些视频。

这样做我使用v3 youtube api

上传了视频

这是用于添加标题的代码的一部分,描述等。

 snippet.setTitle("Test Upload via Java on " + cal.getTime());
      snippet.setDescription(
          "Video uploaded via YouTube Data API V3 );

      // Set your keywords.
      List<String> tags = new ArrayList<String>();
      tags.add("test");
      tags.add("example");
      tags.add("java");
      tags.add("YouTube Data API V3");
      tags.add("erase me");
      snippet.setTags(tags);

我想添加catagotyid所以我只需添加:

snippet.setCategoryId("test");

此时上传代码停止工作,为什么?

to retrieve all the video that upload by my app i need to fill in part line "snippet" (without Quotes) and in id line add my category id like "test" (without Quotes), and then result catch by json ?

更新:

我应该如何填写"try it!"?收到catagoryID的列表,并假设我得到了列表,我怎么知道选择哪个类别?,我想我错过了什么,我不知道是什么

1 个答案:

答案 0 :(得分:0)

尝试GET请求:

https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&regionCode=US&key={YOUR_API_KEY}

当然你用钥匙替换{YOUR_API_KEY}。你应该得到这样的东西:

{
 "kind": "youtube#videoCategoryListResponse",
 "etag": "\"Fn7tolrWrLXf7uknBpwCU9OfMA8/jOw8Jx4EQq_udW-0UgiRcCMWqWQ\"",
 "items": [
  {
   "id": "1",
   "kind": "youtube#videoCategory",
   "etag": "\"Fn7tolrWrLXf7uknBpwCU9OfMA8/gljmmWdkbtlCrMi74KVYLrbTaIA\"",
   "snippet": {
    "channelId": "UCBR8-60-B28hp2BmDPdntcQ",
    "title": "Film & Animation"
   }
  },
  {
   "id": "2",
   "kind": "youtube#videoCategory",
   "etag": "\"Fn7tolrWrLXf7uknBpwCU9OfMA8/n1RtRMaPpKgph8MvS9wf742Tm5U\"",
   "snippet": {
    "channelId": "UCBR8-60-B28hp2BmDPdntcQ",
    "title": "Autos & Vehicles"
   }
  },
  {
   "id": "10",
   "kind": "youtube#videoCategory",
   "etag": "\"Fn7tolrWrLXf7uknBpwCU9OfMA8/1LzYK9Uf9Nt0hzBqNqhuHw0LPI0\"",
   "snippet": {
    "channelId": "UCBR8-60-B28hp2BmDPdntcQ",
    "title": "Music"
   }
  },