php - 使用Youtube API检索视频标题和关联ID

标签 php youtube youtube-api domdocument

我一直在尝试检索相关视频标题和相关ID的列表。 api网址是:https://gdata.youtube.com/feeds/api/videos/FYpunY-gXxU/related?v=2

我的代码一直在解析etag,尽管获取“link-> alternate”值更容易。可以在XPath中找到该值:/ feed / entry [1] / link [1] @rel。我一直在使用DOMDocument尝试此操作,因此将不胜感激。谢谢。

最佳答案

尝试以下代码。您将检索 View 和标题。要检索更多数据,请查看https://gdata.youtube.com/feeds/api/videos/FYpunY-gXxU?v=2&alt=json并尝试弄清楚自己(最佳实践;))

    $JSON = file_get_contents("https://gdata.youtube.com/feeds/api/videos/FYpunY-gXxU?v=2&alt=json");
    $JSON_Data = json_decode($JSON);
    $views = $JSON_Data->{'entry'}->{'yt$statistics'}->{'viewCount'}; //Title
    $title = $JSON_Data->{'entry'}->{'title'}->{'$t'};
    $title = str_replace('"','"',$titel);

关于php - 使用Youtube API检索视频标题和关联ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24705478/

相关文章:

php - 单击复选框时立即更新 mysql 数据库

php - 阿罗哈编辑器 : Inserting images/pictures

asp.net-web-api - YouTube API刷新 token 流程

css - Youtube 视频作为特定部分的背景

ios - 播放 YouTube 播放器的事件

android - 如何将 youtube 视频 URL 传递给 android Studios 中的新 Activity ?

php - Paypal POST返回

php - CodeIgniter Helper Functions 可以使用数据库函数吗?

video - 在没有 Flash 的情况下在 HTML5 中嵌入 YouTube 视频

oauth - 如何手动获取Google OAuth token ?