如何在Android中使用youtube data api v3获取喜欢和不喜欢的视频?

时间:2015-02-27 06:34:49

标签: android youtube-api youtube-data-api

我正在尝试获取频道的所有视频。我正在获取视频ID和缩略图等...但我无法获得喜欢,喜欢和评论视频的数量。

例如:这里我在下面的网址中使用BBC新闻频道ID。

https://www.googleapis.com/youtube/v3/search?key={MY API KEY}&channelId=UC16niRr50-MSBwiO3YDb3RA&part=snippet,id&order=date&maxResults=20

有了这个网址,我会收到viedo信息但不喜欢,不喜欢和评论单个视频的数量。

请帮帮我。 TIA

2 个答案:

答案 0 :(得分:4)

搜索结果只包含基本信息。然后,您必须从搜索结果中获取视频ID,并制作单独的API请求以获取视频所需的详细信息。

https://www.googleapis.com/youtube/v3/videos?key={MY API KEY}&part=statistics&id={IDs}

ID是您从搜索中检索到的视频ID的逗号分隔列表。

答案 1 :(得分:0)

无法在单个api调用中获取搜索结果以及所有视频信息(如count等)。但是,您可以通过编程方式实现它
1)首先获得搜索结果
2)获取每个结果的视频信息以触发另一个api呼叫

您可以通过将部分指定为 contentDetails,statistics,snippet

来获取视频的所有详细信息
payload = {'id': search_result["id"]["videoId"], 'part': 'contentDetails,statistics,snippet', 'key': DEVELOPER_KEY}
l = requests.Session().get('https://www.googleapis.com/youtube/v3/videos', params=payload)    
print l.text

回复如下:

{
 "kind": "youtube#videoListResponse",
 "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/EMbbi9ruIqgq1ERymR5oC-ODvkE\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#video",
   "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/nk4zkCbyR6ftbwbccNAGvGN4ay0\"",
   "id": "gm0iQQyKHlQ",
   "snippet": {
    "publishedAt": "2017-05-05T04:33:36.000Z",
    "channelId": "UCsvNpjj4RxIRXnY9lOeTq-g",
    "title": "Kasaba Malayalam Full Movie | Latest Mammootty Movie |  New Malayalam Film | Mammootty Movies",
    "description": "latest mammootty malayalam movie full HD\nkasaba malayalam movie\nmalayalam new films",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/gm0iQQyKHlQ/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/gm0iQQyKHlQ/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/gm0iQQyKHlQ/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/gm0iQQyKHlQ/sddefault.jpg",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "https://i.ytimg.com/vi/gm0iQQyKHlQ/maxresdefault.jpg",
      "width": 1280,
      "height": 720
     }
    },
    "channelTitle": "malayalam new films",
    "tags": [
     "malayalam new films",
     "new movies",
     "new movies 2017 full movies",
     "latest movies",
     "malayalam movie new",
     "malayalam film",
     "malayalam film new",
     "malayalam full movie",
     "new",
     "film",
     "movie",
     "cinema",
     "songs",
     "kasaba malayalam movie",
     "kasaba",
     "kasaba full movie",
     "kasaba hot",
     "kasaba songs",
     "kasaba scenes",
     "kasaba movie",
     "kasaba full movie online",
     "mammootty",
     "mammootty malayalam full movie",
     "mammootty new movie trailer",
     "mammootty songs",
     "mammootty great father",
     "puthan panam",
     "Varalaxmi Sarathkumar",
     "Neha Saxena"
    ],
    "categoryId": "1",
    "liveBroadcastContent": "none",
    "localized": {
     "title": "Kasaba Malayalam Full Movie | Latest Mammootty Movie |  New Malayalam Film | Mammootty Movies",
     "description": "latest mammootty malayalam movie full HD\nkasaba malayalam movie\nmalayalam new films"
    }
   },
   "contentDetails": {
    "duration": "PT2H15M59S",
    "dimension": "2d",
    "definition": "hd",
    "caption": "false",
    "licensedContent": true,
    "regionRestriction": {
     "blocked": [
      "IN"
     ]
    },
    "projection": "rectangular"
   },
   "statistics": {
    "viewCount": "437181",
    "likeCount": "1135",
    "dislikeCount": "391",
    "favoriteCount": "0",
    "commentCount": "40"
   }
  }
 ]
}