如何通过YouTube API查看视频中的喜欢和不喜欢

时间:2017-03-15 11:14:21

标签: php youtube google-api google-api-php-client youtube-data-api

如何获取每个视频的不喜欢和喜欢?我无法在文档

中找到它
$youtube = new Google_Service_YouTube($client);

$searchResponse = $youtube->search->listSearch('id,snippet', array(
    'type' => 'video',
    'channelId' => 'UCCQeAYn0EfUNp2-RpJKbG5Q'
));


foreach($searchResponse['items'] as $result) {
$videoID = $result['modelData']['id']['videoId'];
$thumb = $result['modelData']['snippet']['thumbnails']['high']['url'];
$title = $result['modelData']['snippet']['title'];
$description = $result['modelData']['snippet']['description'];
// likes
}

1 个答案:

答案 0 :(得分:1)

Search: list仅返回您要搜索的视频列表。要获得有关视频的其他信息,您需要参考。  Videos: list添加part=statistics您要求提供视频统计信息。

请求:

https://www.googleapis.com/youtube/v3/videos?part=statistics&id=dQw4w9WgXcQ&key=yourkey

响应:

{
 "kind": "youtube#videoListResponse",
 "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/8SpkSG4HF2m1G_UwLNJSMOMb1ws\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#video",
   "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/OZ6HKyY4VjtP3NjwRxAIOM14bts\"",
   "id": "dQw4w9WgXcQ",
   "statistics": {
    "viewCount": "293285349",
    "likeCount": "1803097",
    "dislikeCount": "87376",
    "favoriteCount": "0",
    "commentCount": "413069"
   }
  }
 ]
}

抱歉,我不是一个PHP开发人员,因此对代码的帮助不大。