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



Question:

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?


Solution: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


Solution: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?


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »