C
C
CapitanFreeloader2016-10-26 16:32:21
YouTube
CapitanFreeloader, 2016-10-26 16:32:21

How to get more than 50 videos with youtube api v3?

Faced with YouTube api v3
Need to get ~1000 videos on request. Now this is not done using the YouTube API.
Found the pagetoken parameter in the docks. But I can not understand how to use it and where to get it. There is no clear information on google either. Who can advise properly?
Now we get this line:

https://www.googleapis.com/youtube/v3/search?part=snippet&q=$keyword&type=video&maxResults=50&key=$api_token

Getting curled like this
function send_req($url) 
  {
     $ch = curl_init();
    curl_setopt($ch, CURLOPT_USERAGENT,				"Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 		FALSE);
    curl_setopt($ch, CURLOPT_HEADER,				false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,		true);
    curl_setopt($ch, CURLOPT_URL,					$url);
    curl_setopt($ch, CURLOPT_REFERER,				$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,		TRUE);
    $out = curl_exec($ch);
    curl_close($ch);
    return $out;
  }

Tell me how to get more than 50 videos? Perhaps not through pageToken is it possible?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
CapitanFreeloader, 2016-10-26
@CapitanFreeloader

I answer myself:

function send_req($url) 
  {
     $ch = curl_init();
    curl_setopt($ch, CURLOPT_USERAGENT,				"Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 		FALSE);
    curl_setopt($ch, CURLOPT_HEADER,				false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,		true);
    curl_setopt($ch, CURLOPT_URL,					$url);
    curl_setopt($ch, CURLOPT_REFERER,				$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,		TRUE);
    $out = curl_exec($ch);
    curl_close($ch);
    return $out;
  }

$url = "https://www.googleapis.com/youtube/v3/search?part=snippet&q=$keyword&type=video&maxResults=50&key=$api_token";
$res = json_decode(send_req($url));
echo "<pre>";
print_r($res);
echo "<hr>";

$pagetoken = $res->nextPageToken;

$url = "https://www.googleapis.com/youtube/v3/search?part=snippet&q=$keyword&type=video&maxResults=50&pageToken=$pagetoken&key=$api_token";
$res = json_decode(send_req($url));
print_r($res);

E
Evgeny Vorobyov, 2017-12-19
@lokki00003

There is too much.
It is superfluous to include the curl library
Working with api is available through a simple get_contents

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question