E
E
Evgeny Konkin2015-07-07 17:18:41
YouTube
Evgeny Konkin, 2015-07-07 17:18:41

Youtube API v3 Duration?

Hi all!
I'm trying to get the duration of a youtube video, I looked through all the information on stackoverflow, but for some reason the request does not work for me!
Can you tell me what's wrong, I don't know what to do anymore?
Here is my code (Outputs nothing!):

$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);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2015-07-07
@konnn

Perhaps your key does not fit.

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

Check if you are making API requests from the same IP
{
"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."
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question