duanchique1196
2018-03-06 06:37
浏览 137
已采纳

如何用视频ID显示Youtube 10 Trending Video?

please help how to display youtube 10 trending video with video ID.

i using this code but not show video id help. but correctly show trending video.

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

图片转代码服务由CSDN问答提供 功能建议

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

我使用此代码但不显示视频ID帮助。 但正确显示趋势视频。

  function CURL($ url){
 $ ch = curl_init(); 
 curl_setopt($ ch,CURLOPT_URL,$ url); \  n 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); \  n $ 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); 
返回$ load; 
 \  n 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&  amp; 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; 
} 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongpei2835 2018-03-06 06:50
    已采纳

    According to https://developers.google.com/youtube/v3/docs/videos#resource you can able to use just $video->id so just change echo $video->id->videoID to $video->id

    已采纳该答案
    打赏 评论