如何显示带有视频 ID 的 Youtube 10 趋势视频?

How to display Youtube 10 Trending Video with video id?

请帮助如何显示带有视频 ID 的 youtube 10 趋势视频。

我使用此代码但未显示视频 ID 帮助。但正确显示热门视频。

function CURL($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $header[] = "Accept-Language: en";
    $header[] = "User-Agent: $uaa";
    $header[] = "Pragma: no-cache";
    $header[] = "Cache-Control: no-cache";
    $header[] = "Accept-Encoding: gzip,deflate";
    $header[] = "Content-Encoding: gzip";
    $header[] = "Content-Encoding: deflate";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    $load = curl_exec($ch);
    curl_close($ch);
    return $load;

     return file_get_contents($url);
}

$grab = CURL('https://www.googleapis.com/youtube/v3/videos?key=AIzaSyAjMsVN8Q-sUQHnc9qv7D9cA0X0xhcqrec&part=id,snippetcontentDetails&chart=mostPopular&regionCode=US&maxResults=10&type=video');

$json = json_decode($grab);

foreach ($json->items as $video)
{
echo $video->id->videoId;
echo $video->snippet->title;
echo $video->snippet->description;
echo $video->snippet->channelTitle;
echo $video->snippet->channelId;
}

根据 https://developers.google.com/youtube/v3/docs/videos#resource 你可以只使用 $video->id 所以只需将 echo $video->id->videoID 更改为 $video->id