R
R
rinaz222019-06-02 17:29:32
PHP
rinaz22, 2019-06-02 17:29:32

Why is nothing coming out when requesting the youtube API?

Hello! I found a php code on the Internet that makes a request to the youtube API. When you run it, nothing comes out (just NULL).

function youtube_search($apikey, $search, $limit){
  $search =  urlencode($search);
  $url = "https://www.googleapis.com/youtube/v3/search?part=snippet&q=$search&type=video&maxResults=$limit&regionCode=RU&key=$apikey";
  $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;
}
$search = "Покемоны"; //  Поисковый запрос
$limit = 10; // Количество результатов
$apikey = "{ API_KEY }"; // Ваш ключ к api youtube v3
$res_json = youtube_search($apikey, $search, $limit) ;
$res = json_decode( $res_json );
 
print_r($res);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lukoie, 2019-06-02
@lukoie

https://klisl.com/YouTube_API.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question