Skip to content

Getting YouTube user avatar/profile picture by User ID

http(s)://i(1-4).ytimg.com/i/(user_id)/1.jpg

For example, my YouTube channel (himself0890) User ID is: zRJMLe36PT0Q2mhlmbU2OQ

So, my avatar url could be: https://i3.ytimg.com/i/zRJMLe36PT0Q2mhlmbU2OQ/1.jpg or it could be https://i2.ytimg.com/i/zRJMLe36PT0Q2mhlmbU2OQ/1.jpg

I had the issue in Python when retrieving the User ID from the newsubscriptionvideos feed…


So, I recently ran into the problem where YouTube doesn’t return the author’s profile picture in their feed (specifically the newsubscriptionvideos feed).

After checking out some of the XML they gave me back, I noticed that if I hit their newsubscriptionvideos v2 API, the Author element contains the “ns1:userId” tag.

If you have any questions on how to parse this tag for the user ID in Python, feel free to drop a comment and I’ll help you out.

3 Comments

  1. Hello, I have found this methodolgy does not always work. Also, because it is not contained in Google documentation, it is not guaranteed to always be available. I have discovered an alternate way of display the profile picture of a given username using a little piece of javascript to get and then display the picture from the youtube feed api.

    Basically you can make a call to this url: http://gdata.youtube.com/feeds/api/users/%5Busername%5D?fields=yt:username,media:thumbnail,title&alt=json-in-script&format=5&callback=showYouTubeProfileInfo replacing the [username] with the user you want. This url returns the results as a json wrapped in a .js file which will call the javascript function provided in the paramter ‘callback’. e.g. function showYouTubeProfileInfo(data)
    {
    document.getElementById(‘userprofile’).innerHTML = ” “;
    }

    This then enables you to process the returned data and display it.

    I have got sample code here http://daniel-mitchell.com/blog/display-youtube-user-avatar-profile-picture-by-username/ which you can use.

  2. Hello. Sorry it seems some of the javascript in my above comment has been stripped out. The innerHTML should contain a image tag with the src set to: data.entry.media$thumbnail.url

    Hope that helps.

Leave a Reply

Your email address will not be published. Required fields are marked *