0

I can get a list of videos from a channel I'm querying. I have most of the information I need in an existing api call, but I'd really like to also get the number of times each video has been viewed.

My current query gives me 50 results:

https://www.googleapis.com/youtube/v3/search?part=id,snippet&key=' . $key . '&channelId=' . $channelId . '&order=date&maxResults=50&publishedBefore=' . $publishedBefore

I read I can get viewCounts through the API by providing a video id. But that's one at a time. I'm hoping I can ammend my query above to also output the viewCounts to make 1 query instead of 51 queries.

I have a part attribute that I can set to "a comma-separated list of one or more search resource properties that the API response will include." The examples I've seen have "id,snippet", but can I specify a value that will provide how many times the video has been viewed? I can't find a list of search resource properties.

Also, is there a way to view a channel's "hottest" or "trendiest" videos that they currently have?

GFL
  • 1,278
  • 2
  • 15
  • 24

1 Answers1

1

You can make one single request which get statistics from youtube API. You need to call API like this

https://content.googleapis.com/youtube/v3/videos?id=Ks-_Mh1QhMc,Cc0KYU2j0TM4,CeIho2S0ZahI&part=statistics&key={APIKEY}

In this request I am getting data from 3 videoId, you can get upto 50 videos at a time.

Anirudha Gupta
  • 9,073
  • 9
  • 54
  • 79