问题 通过API获取YouTube视频的喜欢/不喜欢的数量?


如何获得YouTube视频的喜欢/不喜欢的数量 YouTube API


5896
2017-09-01 14:48


起源



答案:


您可以像这样查询YouTube API:

<?php

$curlhandle = curl_init();
curl_setopt($curlhandle, CURLOPT_URL, "http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=computers&max-results=10&orderby=viewCount");
curl_setopt($curlhandle, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($curlhandle);
curl_close($curlhandle);

$json = json_decode($response);


foreach ($json->data->items as $result)
{

        echo '<div class="video"><a href="'.$result->player->default.'" target="_blank">';
        echo '<img src="'.$result->thumbnail->hqDefault.'">';
        echo ' <div class="title"> '.$result->title.'</div><div class="rating">'.$result->likeCount.'</div></a></div>';
        //print_r($result);

}

?>


10
2017-10-18 16:50



这里的关键部分是添加 v=2 查询参数。喜欢和不喜欢不会出现在API的第一个版本中。 - johnf


答案:


您可以像这样查询YouTube API:

<?php

$curlhandle = curl_init();
curl_setopt($curlhandle, CURLOPT_URL, "http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=computers&max-results=10&orderby=viewCount");
curl_setopt($curlhandle, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($curlhandle);
curl_close($curlhandle);

$json = json_decode($response);


foreach ($json->data->items as $result)
{

        echo '<div class="video"><a href="'.$result->player->default.'" target="_blank">';
        echo '<img src="'.$result->thumbnail->hqDefault.'">';
        echo ' <div class="title"> '.$result->title.'</div><div class="rating">'.$result->likeCount.'</div></a></div>';
        //print_r($result);

}

?>


10
2017-10-18 16:50



这里的关键部分是添加 v=2 查询参数。喜欢和不喜欢不会出现在API的第一个版本中。 - johnf


如果您使用的是Java API,那么您可能会得到如下不喜欢的内容:

YtRaing ytRating = videoEntry.getYtRating();
int likes = ytRating.getNumLikes();
int dislikes = ytRating.getNumDislikes();

videoEntry是来自(com.google.gdata.data.youtube.VideoEntry)的VideoEntry变量


3
2017-11-22 06:21





如果你想知道不喜欢的地方,dislikeCount = ratingCount - likeCount


3
2018-04-25 16:25





喜欢数,可以通过设置获取不喜欢 部分 如 统计

下面是python代码:

payload = {'id': search_result["id"]["videoId"], 'part': 'statistics', 'key': DEVELOPER_KEY}
l = requests.Session().get('https://www.googleapis.com/youtube/v3/videos', params=payload)    
print l.text

回复将是:

{
 "kind": "youtube#videoListResponse",
 "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/0NR0uhQMzlaae_et8wHFZKsdFPA\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#video",
   "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/vBL_50n3XI1eQcsdivfxN_g9c2M\"",
   "id": "hMncTg0iBko",
   "statistics": {
    "viewCount": "10281",
    "likeCount": "61",
    "dislikeCount": "9",
    "favoriteCount": "0",
    "commentCount": "1"
   }
  }
 ]
}

0
2018-05-12 23:31