AddcitedToLearn
AddcitedToLearn

Reputation: 398

How to retrive likes and dislikes on a video via the YouTube API

How to get the dislikes and likes for each video ? I can't find it in the documentation

$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
}

Upvotes: 0

Views: 707

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116986

Search: list only returns a list of the videos you are searching on. To get additional information about the video in question you need to go though. Videos: list by adding part=statistics you are requesting the stats for the video.

Request:

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

Response:

{
 "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"
   }
  }
 ]
}

Sorry I am not a PHP dev so cant really help much with he code.

Upvotes: 1

Related Questions