如何使用YouTube API从YouTubeVideoFeed对象获取公共频道URL? [英] How to get the public channel URL from YouTubeVideoFeed object using the YouTube API?

查看:238
本文介绍了如何使用YouTube API从YouTubeVideoFeed对象获取公共频道URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python版本的YouTube API通过以下网址获取YouTubeVideoFeed对象:

I'm using the Python version of the YouTube API to get a YouTubeVideoFeed object using the following URL:

http://gdata.youtube.com/feeds/api/users /USERNAME/上传

注意:我已经用需要关注的帐户替换了USERNAME.

到目前为止,获取提要,迭代条目,获取播放器网址,标题和缩略图都非常简单.但是现在我想在页面上添加一个访问频道"链接.我无法弄清楚如何从供稿中获取频道(在这种情况下,是用户的默认频道)的公共" URL.据我所知,唯一直接存储在供稿中的URL指向http://gdata.youtube.com/,而不是 公共站点.

So far getting the feed, iterating the entries, getting player urls, titles and thumbnails has all been straightforward. But now I want to add a "Visit Channel" link to the page. I can't figure out how to get the "public" URL of a channel (in this case, the default channel from the user) out of the feed. From what I can tell, the only URLs stored directly in the feed point to the http://gdata.youtube.com/, not the public site.

如何基于提要链接到频道?

How can I link to a channel based on a feed?

推荐答案

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

Well, the youtube.com/user/USERNAME is a pretty safe bet if you want to construct the URL yourself, but I think what you want is the link rel='alternate'

您必须从Feed中获取链接数组,并进行迭代以找到备用链接,然后获取href

You have to get the link array from the feed and iterate to find alternate, then grab the 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=用户名

最正确的方法是从用户个人资料供稿中获取备用"链接,因为从技术上讲,上述URL指向上传的视频,而不是主频道页面

The most correct thing would be to grab the 'alternate' link from the user profile feed, as technically the above URL goes to the uploaded videos, not the main channel page

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

这篇关于如何使用YouTube API从YouTubeVideoFeed对象获取公共频道URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆