0
votes

I'm trying to build website (for my own) that show me 5 latest videos from 20 channels in youtube. So I'm using for each specific channel in this following request:

https://www.googleapis.com/youtube/v3/search?key={API_KEY}&channelId={CHANNEL_ID}&part=snippet,id&order=date&maxResults=5

Each requst cost 100 unit, and for 20 channel is 2000 units, and I have just 10,000 units/day because the quota of youtube API. And because I trying to figure out how it works, and sometimes there are bugs too, I useing the same request many times, and my quota runs out fast.

So my quastion is: is there any way to replace the SEARCH request in, CHANNEL/VIDEOS (list) request to reduce the cost of the request (this cost is just 1 unit). Or maybe to get in one request all the 5 videos from all the 20 channels?

Sorry for my English if there are any mistakes Thanks in advance from everyone.

1

1 Answers

0
votes

You may employ the Activities.list API endpoint, queried with:

  • channelId=CHANNEL_ID,
  • part=snippet,contentDetails,
  • fields=items(snippet(type,publishedAt),contentDetails(upload)), and
  • publishedAfter=....

where CHANNEL_ID varies among all the IDs of the channels of your interest (thus N channels implying N endpoint calls).

You're supposed to compute a meaningful publishedAfter value to be passed to the endpoint. Attach such a value to each channel you're monitoring within your app, and maintain it to be 1 second plus the value of publishedAt property corresponding to the newest video of that channel.

Initializing/resetting this per channel datetime value is done simply upon issuing an endpoint call without the publishedAfter parameter.

According to the docs, you'll get from this endpoint a result set made of Activities resource items that would contain the following info:

contentDetails.upload (object)
The upload object contains information about the uploaded video. This property is only present if the snippet.type is upload.

contentDetails.upload.videoId (string)
The ID that YouTube uses to uniquely identify the uploaded video.

The official docs state that each call to Activities.list endpoint has a quota cost of one unit.