Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PHP – How do we can get Youtube Views and comments count along with videos list via Youtube APIs?

I am getting list of videos from youtube API. I want to also get views and comment count in response from youtube apis.

I am trying the following.

$client = new \Google_Client();
$client->setApplicationName('API code samples');
$client->setDeveloperKey('api_key');
echo "<pre>";
$queryParams = [
    'channelId' => 'channel_id',
    'maxResults' => 5,
    'order' => 'date',
    'type' => 'video'
];

$response = $service->search->listSearch('snippet', $queryParams);
print_r($response);

Youtube API Response

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[snippet] => Google\Service\YouTube\SearchResultSnippet Object
    (
        [channelId] => Channel_id
        [channelTitle] => JoĂŁo PatrĂ­cio
        [description] => Mohamed Said made an amazing video demonstrating how to easily develop a Nuxt and Laravel API application, and now let's ...
        [liveBroadcastContent] => none
        [publishedAt] => 2021-12-08T08:57:21Z
        [thumbnailsType:protected] => Google\Service\YouTube\ThumbnailDetails
        [thumbnailsDataType:protected] => 
        [title] => Deploying LaravelAPI and NuxtJs App using Traefik and Docker - 2nd Episode

I am getting vidoes title, description etc
is it possible to get video’s views & comments count in same api response?

Help me pls. Thank you

>Solution :

I am getting vidoes title, description etc is it possible to get video’s views & comments count in same api response?

No it is not posible.

Search.list method

You are using the search.list method Which returns a list of search#resource

{
  "kind": "youtube#searchResult",
  "etag": etag,
  "id": {
    "kind": string,
    "videoId": string,
    "channelId": string,
    "playlistId": string
  },
  "snippet": {
    "publishedAt": datetime,
    "channelId": string,
    "title": string,
    "description": string,
    "thumbnails": {
      (key): {
        "url": string,
        "width": unsigned integer,
        "height": unsigned integer
      }
    },
    "channelTitle": string,
    "liveBroadcastContent": string
  }
}

Video.list method

To get a rating back you would need to use videos.list which will return a video resource
which does contain the stats your are looking for.

  "statistics": {
    "viewCount": unsigned long,
    "likeCount": unsigned long,
    "dislikeCount": unsigned long,
    "favoriteCount": unsigned long,
    "commentCount": unsigned long
  },
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading