konnn
@konnn
Front-end developer

Youtube API v3 Duration?

Привет всем!
Пытаюсь получить длительность youtube видео, просмотрел всю инфу на stackoverflow, но у меня почему-то не работает запрос!
Подскажите может что не так, уже не знаю что делать?

Вот мой код (Ничего не выводит!):
$videoID = "YPVXlGY_tAc";
$apikey = "AIzaSyBA0L0QG8E5eVZlu-GEOeI5Ir3cr54zips";
$get_video = file_get_contents("https://www.googleapis.com/youtube/v3/videos?id=$videoID&key=$apikey&part=contentDetails");
$content = json_decode($get_video, true);
foreach ($content['items'] as $details) {
	$duration = $details['contentDetails']['duration'];
	echo("Длительность: ".$duration);
}
  • Вопрос задан
  • 1584 просмотра
Решения вопроса 1
BuriK666
@BuriK666
Компьютерный псих
Возможно Ваш ключик не подходит.
PHP Warning:  file_get_contents(https://www.googleapis.com/youtube/v3/videos?id=YPVXlGY_tAc&key=AIzaSyBA0L0QG8E5eVZlu-GEOeI5Ir3cr54zips&part=contentDetails): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
 in php shell code on line 1


Проверьте с того ли IP вы делаете запросы к API
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "ipRefererBlocked",
"message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.",
"extendedHelp": "https://console.developers.google.com"
}
],
"code": 403,
"message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed."
}
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы