F
F
FEDKOTV2019-12-18 03:08:29
YouTube
FEDKOTV, 2019-12-18 03:08:29

How to get the latest videos from youtube if requests to its API are quickly scooped up?

There is a script with the following content:

$videoList = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelID.'&maxResults='.$maxResults.'&key='.$API_key.''));

  foreach($videoList->items as $item){
      //Embed video
      if(isset($item->id->videoId)){
          echo '<div class="video">
 					<iframe width="100%" class="youtube-video" src="https://www.youtube.com/embed/'.$item->id->videoId.'"  frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
 				</div>';
      }
  }

Created a gmail account, generated a new API key, and enabled the Youtube API v3 service for the account.
After, I implemented the script on the main page of the test site, the result displayed the last 3 videos from the channel. Everything worked, but after a couple of hours there are no vidos.
I checked the API - it says that I have reached the threshold / quota of requests to the API. And there are as many as 10k of them, but how I (?) managed to spend them all I can’t imagine.
Then I used the API key from two more of my accounts, which also reached the threshold in a couple of hours.
Question: How can I make the script work, the Youtube API provides what is required of it, or am I using it incorrectly? Does anyone have a reasonable explanation why all three of my accounts reached the limit so quickly, provided that 2-3 people worked on the site?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
antonwx, 2019-12-18
@antonwx

Do not use the API, pull the page, emulating the browser, and parse it

I
igotDiamonds, 2019-12-18
@igotDiamonds

https://developers.google.com/youtube/v3/determine...
Judging by the fact that you use the search resource, 100 quota units are charged for one request, if the channel is yours, then change the method of sending the request, for example, to videos, then each request will only cost 3

P
prishelec, 2019-12-20
@prishelec

read
https://github.com/ytdl-org/youtube-dl
download
https://github.com/ytdl-org/youtube-dl/releases
and forget about limits

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question