Search code examples
javascriptyoutube-apiyoutube-data-api

Youtube get image url from channel (not getting image)


I am trying to get the profile image of a youtube channel via direct url.

I found this:

https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&id={CHANNEL_ID}&key={GOOGLE_API_KEY}

But after after adding the channel id and my google api key I get this returned:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"0Fu6lI6VPydRdlQU3wwNfowdAUs/hirftF6Hp1SlcHf-VOY2asqIoJA\"",
 "pageInfo": {
  "totalResults": 0,
  "resultsPerPage": 0
 },
 "items": []
}

I need a direct link to the image so I can add it to

How can I do that?


Solution

  • Try this url:

    GET https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername={CHANNEL}&key={YOUR_API_KEY}
    

    It produces (Channel is FailArmy in this case):

    {
      ...
      "thumbnails": {
         "default": {
          "url": "https://yt3.ggpht.com/-_8lHSPO3nNI/AAAAAAAAAAI/AAAAAAAAAAA/-THVRONaQco/s88-c-k-no-rj-c0xffffff/photo.jpg"
         },
         "medium": {
          "url": "https://yt3.ggpht.com/-_8lHSPO3nNI/AAAAAAAAAAI/AAAAAAAAAAA/-THVRONaQco/s240-c-k-no-rj-c0xffffff/photo.jpg"
         },
         "high": {
          "url": "https://yt3.ggpht.com/-_8lHSPO3nNI/AAAAAAAAAAI/AAAAAAAAAAA/-THVRONaQco/s240-c-k-no-rj-c0xffffff/photo.jpg"
         }
        },
        ...
    }
    

    Update:

    You can get the default url for example with: response.items[0].snippet.thumbnails.default.url