最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get Youtube channel picture via username? - Stack Overflow

programmeradmin0浏览0评论

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: munitychannel
and I want to get the following thumbnail picture:
.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:

/[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 acplish the requirement? Thanks!! ;-)

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: munitychannel
and I want to get the following thumbnail picture:
http://i2.ytimg./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./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 acplish the requirement? Thanks!! ;-)

Share Improve this question edited Mar 29, 2013 at 10:37 ChrisF 137k31 gold badges264 silver badges334 bronze badges asked Aug 26, 2010 at 4:46 firestokefirestoke 1,05911 silver badges23 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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

  • http://gdata.youtube./feeds/api/users/munitychannel

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./feeds/api/users/munitychannel?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 munitychannel 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;

发布评论

评论列表(0)

  1. 暂无评论