既然API v2已经消失了,那么在没有v3 API的情况下,如何获得频道的简单RSS提要?如果目标是提要阅读器,我对Yahoo Pipes或任何比为v3 API创建应用程序更简单的解决方法开放.我只需要一个RSS提要.到目前为止它已公开发布,现在可以停止任何一分钟(我认为).那么为什么不在没有API密钥的情况下访问它呢?
Ait*_*orF 97
在RSS阅读器部分https://support.google.com/youtube/answer/6098135?hl=en,您可以选择将订阅导出到OPML文件.然后,查看OPML的内容,您可以提取提要,每个提要的结构是:
https://www.youtube.com/feeds/videos.xml?channel_id=XXXX
因此,如果您知道频道ID,则可以从此结构生成新的Feed.这种Feed没有收到" https://youtube.com/devicesupport "错误,所以我希望他们会继续工作.
Pri*_*ome 58
您可以像这样获取Feed:
https://www.youtube.com/feeds/videos.xml?channel_id=CHANNELID
https://www.youtube.com/feeds/videos.xml?user=USERNAME
https://www.youtube.com/feeds/videos.xml?playlist_id=YOUR_YOUTUBE_PLAYLIST_NUMBER
Run Code Online (Sandbox Code Playgroud)
但是不再支持以前支持的JSON格式(带有附加参数&alt=JSON).
此外,您可以从开发者控制台请求API密钥以公开访问您的YouTube视频,并以JSON格式获取YouTube视频,播放列表,如下所示:
- Get Channels:
https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails&forUsername={YOUR_USER_NAME}&key={YOUR_API_KEY}
- Get Playlists:
https://www.googleapis.com/youtube/v3/playlists?part=snippet%2CcontentDetails&channelId={YOUR_CHANNEL_ID}&key={YOUR_API_KEY}
- Get Playlist Videos:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails%2Cstatus&playlistId={YOUR_PLAYLIST_ID}&key={YOUR_API_KEY}
Run Code Online (Sandbox Code Playgroud)
来自YouTube v3文档的更多信息.
小智 10
在你的管中,点击左侧窗格上的订阅.这将打开页面中心的所有订阅.向下滚动,您将找到"导出到RSS阅读器"按钮,该按钮会生成所有订阅的xml文件.我已经完成了这个并将其添加到我喜欢的RSS阅读器中.
如果你检查任何Youtube频道页面,<head>你会在里面找到一个这样的rss元节点:
<link rel="alternate"
type="application/rss+xml" title="RSS"
href="https://www.youtube.com/feeds/videos.xml?channel_id=UCn8zNIfYAQNdrFRrr8oibKw">
Run Code Online (Sandbox Code Playgroud)
这应该为您提供所需的数据.
小智 6
通过在 YouTube 频道页面的源代码中搜索属性 data-channel-external-id 来获取频道 id。(感谢 helq)。
此代码将从提要中获取所有视频标题和 ID,并将其转储到一个数组中:
$channel_id = 'XXX'; // put the channel id here
$youtube = file_get_contents('https://www.youtube.com/feeds/videos.xml?channel_id='.$channel_id);
$xml = simplexml_load_string($youtube, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);
$youtube = json_decode($json, true);
$yt_vids = array();
$count = 0;
foreach ($youtube['entry'] as $k => $v) {
$yt_vids[$count]['id'] = str_replace('http://www.youtube.com/watch?v=', '', $v['link']['@attributes']['href']);
$yt_vids[$count]['title'] = $v['title'];
$count++;
}
print_r($yt_vids);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
93576 次 |
| 最近记录: |