python - 如何使用 YouTube API 从 YouTubeVideoFeed 对象获取公共(public) channel URL?

标签 python youtube feed youtube-api

我使用 Python 版本的 YouTube API 来通过以下 URL 获取 YouTubeVideoFeed 对象:

http://gdata.youtube.com/feeds/api/users/USERNAME/uploads

注意:我已将 USERNAME 替换为我需要关注的帐户。

到目前为止,获取提要、迭代条目、获取玩家 URL、标题和缩略图都非常简单。但现在我想在页面上添加一个“访问 channel ”链接。我不知道如何从提要中获取 channel 的“公共(public)”URL(在本例中为用户的默认 channel )。据我所知,直接存储在 Feed 中的唯一 URL 指向 http://gdata.youtube.com/而不是公共(public)网站。

如何链接到基于 Feed 的 channel ?

最佳答案

嗯,如果您想自己构建 URL,youtube.com/user/USERNAME 是一个非常安全的选择,但我认为您想要的是链接 rel='alternate'

您必须从提要中获取链接数组并迭代以找到替代项,然后获取 href

类似于:

client = gdata.youtube.service.YouTubeService()

feed = client.GetYouTubeVideoFeed('http://gdata.youtube.com/feeds/api/users/username/uploads')

for link in feed.link:
  if link.rel == 'alternate':
    print link.href

输出:

http://www.youtube.com/profile_videos?user=username

最正确的做法是从用户个人资料源中获取“备用”链接,因为从技术上讲,上述 URL 会转到上传的视频,而不是主 channel 页面

feed = client.GetYouTubeUserEntry('http://gdata.youtube.com/feeds/api/users/username')

for link in feed.link:
  if link.rel == 'alternate':
    print link.href

输出: http://www.youtube.com/profile?user=username

关于python - 如何使用 YouTube API 从 YouTubeVideoFeed 对象获取公共(public) channel URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/776110/

相关文章:

python - 如何阅读 RSS 提要中的所有文章?

python - 关键字 "license"在 python 中有什么用?

python - python中的import关键字实际上是如何工作的?

python在写入CSV时添加额外的空行

javascript - 我可以使用网络爬虫将新的 YouTube 视频添加到播放列表吗?

android webview 不使用 WebViewClient 显示视频

python - 为什么 VSCode 在启动调试器之前不激活 conda?

flutter - 如何从 Flutter 应用程序在 google chromecast 中播放 YouTube 视频?

php - 获取实时 NFL 比分/统计数据以进行阅读和操作?

php - 如何组合 mysql 的多个表(以创建流动的新闻源),但仍能区分记录?