Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Youtube channel picture via username?

Tags:

javascript

Any idea?
I checked the Youtube API that doesn't support this feature.
Is it possible?

I need to get the thumbnail picture via username directly.
for example:

I got a username named: communitychannel
and I want to get the following thumbnail picture:
http://i2.ytimg.com/vi/YVrqydZz3e4/default.jpg


Thanks your reply!!
I know I can retrieve thumbnail data by doing this. But the case is, I will get a Youtube member's subscription item list first via the following URL:

http://gdata.youtube.com/feeds/api/users/[USER_NAME]/subscriptions

From the Youtube official document, it indicate that the response data include tag. But I never see it...

If list length is 100, then I need to send total 101 requests to get the thumbnail data for each item. But it will consume too much network bandwidth to do that.

So, is any other way to accomplish the requirement? Thanks!! ;-)

like image 517
firestoke Avatar asked Aug 26 '10 04:08

firestoke


1 Answers

You can get the users image by using a url like this:

  • http://gdata.youtube.com/feeds/api/users/communitychannel

You can get just the username and image thumbnail by appending a query string as described in the partial responses api: ?fields=yt:username,media:thumbnail

  • You can get the response in json format to use easily in javascript by appending: &alt=json-in-script&format=5

  • You can also specify a callback to execute when the response has loaded by appending: &callback=showImage

Your url now looks like this:

http://gdata.youtube.com/feeds/api/users/communitychannel?fields=yt:username,media:thumbnail&alt=json-in-script&format=5&callback=showImage

To use this in a page put it in a script tag like so:

 <script type='text/javascript' src="your_url"/>

and the callback should look like this:

function showImage(data)
{
  var name= data.entry.yt$username.$t;
  var url = data.entry.media$thumbnail.url;
  $(document).append("<img src='"+ url +"'/>");
}

You must make sure that the showImage callback function is defined before you load the data.

I have created a sample of loading a feed and the user images here (Make sure you change communitychannel to your own username or it won't work)

I can't see a better way of reducing your bandwidth than using the partial responses api;

like image 67
pixl coder Avatar answered Sep 22 '22 18:09

pixl coder