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