Youtube在API v3 PHP中获取用户的视频ID

Youtube在API v3 PHP中获取用户的视频ID,php,youtube,Php,Youtube,我使用此代码在我的网站中显示用户的所有视频: <?php $xml = simplexml_load_file('http://gdata.youtube.com/feeds/api/users/XXXXXXX/uploads'); $server_time = $xml->updated; $return = array(); foreach ($xml->entry as $video) { $vid = array(); $vid[

我使用此代码在我的网站中显示用户的所有视频:

<?php
  $xml = simplexml_load_file('http://gdata.youtube.com/feeds/api/users/XXXXXXX/uploads');
  $server_time = $xml->updated;
  $return = array();
  foreach ($xml->entry as $video) {
      $vid = array();
      $vid['id'] = substr($video->id,42);
      $vid['title'] = $video->title;
      array_push($return, $vid);
  }

  ?>
<h2>Video Gallery</h2>
  <?php
  foreach($return as $video) {
    ?>
      <div class="col-md-4">
<div style="height: auto;" class="featured-box featured-box-secundary">
  <div class="box-content clearfix">
<h4><?= $video['title'] ?></h4>
<iframe width="270" height="203" src="https://www.youtube.com/embed/<?=$video['id']?>?rel=0&amp;showinfo=0" allowfullscreen></iframe>
      </div></div></div>
    <?php
  }
?>
更新;
$return=array();
foreach($xml->entry as$video){
$vid=array();
$vid['id']=substr($video->id,42);
$vid['title']=$video->title;
阵列推送($return,$vid);
}
?>
视频画廊

是的,Youtube API V2已经死了

要向Youtube API V3发出请求,您需要经过身份验证。获取
{YOUR_API_KEY}
. 您需要创建并启用Youtube API

之后,可以发出以下命令:

弗斯特
channels#list
方法将返回一个
JSON
,其中包含有关频道的一些信息,包括“上传”播放列表的
{PLAYLIST_ID}

https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername={USERNAME}&key={YOUR_API_KEY}

第二 使用
{PLAYLIST_ID}
可以使用
playlistems#list
方法获取用户上传的视频:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId={PLAYLIST_ID}&key={YOUR_API_KEY}

您可以在以下设备上测试上述代码:


$return的输出是什么?你收到了什么不推荐的通知?该通知是youtube结果中的一个额外视频,包含信息。为什么我需要经过身份验证才能获得用户视频列表?@fran不,如果是,它是您在google API控制台上创建项目后生成的。我想让我的频道视频不播放列表视频,这样做。@HuzoorBux没问题,请使用ID上载播放列表