0
自从2016年3月以来,我一直在使用下面的代码来获取视频持续时间($ vid_dur),直到它今天没有任何问题地使用YouTube API v3,没有任何干预侧。有什么建议么?在YouTube API v3中获取视频持续时间不起作用
<?php
$vidkey = "xxxxxxxxx" ;
$apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ;
$dur = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=$vidkey&key=$apikey");
$VidDuration =json_decode($dur, true);
foreach ($VidDuration['items'] as $vidTime)
{
$VidDuration= $vidTime['contentDetails']['duration'];
}
// convert duration from ISO to M:S
$date = new DateTime('2000-01-01');
$date->add(new DateInterval($VidDuration));
$vid_durH= $date->format('H') ;
if ($vid_durH=="00") {
$vid_dur= $date->format('i:s') ;
}
else {
$vid_dur= $date->format('H:i:s') ;
}
?>
以下是错误消息
Fatal error: Uncaught exception 'Exception' with message 'DateInterval::__construct() [dateinterval.--construct]: Unknown or bad format()'
回显VidDuration以查看DateInterval引发什么错误。 – johnh10
{“error”:{“errors”:[{“domain”:“usageLimits”,“reason”:“keyInvalid”,“message”:“Bad Request”}],“code”:400, “Bad Request”}} –
那么错误消息说,keyInvalid所以看看。 – johnh10