我需要帮助才能使用新的 API 版本从特定用户那里检索 YouTube 视频。
我在 console.developers.google.com 上创建了 YouTube 数据 API
两个 OAuth 和 公共(public) API 访问 对于浏览器。
在我使用此代码检索最新的 6 个视频之前:
$feedURL = 'http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?max-results=6';
$sxml = simplexml_load_file($feedURL);
foreach ($sxml->entry as $entry) {
$watch = (string)$media->group->player->attributes()->url;
}
如何使用 API 3 更新此代码?
最佳答案
我一直在.net 中做类似的事情,但它不像以前那么简单。
它现在需要几个额外的步骤:
第 1 步:您需要通过以下方式获取用户的 channelId:
https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername= {0}&key={1} - 其中 {0} 是 USERNAME,key 是您的 API key
第 2 步:从中您可以通过以下方式获取视频列表:
https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId= {0}&key={1}
第 3 步:
https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,player&id= {0}&key={1} - 其中 id 是从第 2 步返回的 videoId。
希望有帮助。
关于php - YouTube API 3 获取特定用户的最后视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30393289/