Getting YouTube channel profile picture with channelId

◇◆丶佛笑我妖孽 提交于 2019-12-09 05:29:58

问题


So I'm trying to get the channel profile picture for a YouTube channel by using the channelId.

I would like to do it simply by adding the channelId to a URL and get the image that way. Facebook has something similar where you use this URL:

http://graph.facebook.com/user_id/picture?type=square

Google+ has it too, found this question here. Sadly it didn't work for YouTube (I couldn't get it to work)

Hope someone has a solution!

Thanks in advance :)


回答1:


You can use channels->list request for that.

In response you will get snippet.thumbnails."default".url for that

For authenticated user's channel:

GET https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true&fields=items%2Fsnippet%2Fthumbnails&key={YOUR_API_KEY}

Or for any channel ID:

GET https://www.googleapis.com/youtube/v3/channels?part=snippet&id+CHANNEL_ID&fields=items%2Fsnippet%2Fthumbnails&key={YOUR_API_KEY}



回答2:


In PHP, I got it with:

$url = "https://www.googleapis.com/youtube/v3/channels?part=snippet&fields=items%2Fsnippet%2Fthumbnails%2Fdefault&id={$channelId}&key={$API}";

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$channelOBJ = json_decode( curl_exec( $ch ) );

$thumbnail_url = $channelOBJ->items[0]->snippet->thumbnails->default->url;



回答3:


a little bit late, but maybe interesting for others:

just create a comma separated list for the different channelIds and then call

https://www.googleapis.com/youtube/v3/channels?part=snippet&id='+commaSeperatedList+'&fields=items(id%2Csnippet%2Fthumbnails)

therefore you don't have to send a request for each item



来源:https://stackoverflow.com/questions/18280636/getting-youtube-channel-profile-picture-with-channelid

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