How to get the public channel URL from YouTubeVideoFeed object using the YouTube API?

风流意气都作罢 提交于 2019-12-23 01:58:15

问题


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/uploads

Note: I've replaced USERNAME with the account I need to follow.

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?


回答1:


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'

You have to get the link array from the feed and iterate to find alternate, then grab the href

something like:

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

Output:

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

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

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




回答2:


you might be confusing usernames... when I use my username I get my public page http://gdata.youtube.com/feeds/api/users/drdredel/uploads They have some wacky distinction between your gmail username and your youtube username. Or am I misunderstanding your question?



来源:https://stackoverflow.com/questions/776110/how-to-get-the-public-channel-url-from-youtubevideofeed-object-using-the-youtube

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!