Get GitHub avatar from email or name

Github Api

Github Api Problem Overview


I'm trying to get the GitHub user picture (avatar) from users of GitHub.

I've found these API:

https://avatars.githubusercontent.com/<username>
https://avatars.githubusercontent.com/u/<userid>

But I can't find a way to get the avatar from the user email or the user display name. I can't find documentation about that.

Is there some similar URL API to get what I'm looking for?

Github Api Solutions


Solution 1 - Github Api

You can append .png to the URL for the User's profile to get redirected to their avatar. You can add the query param size to specify a size smaller than the default of 460px wide (i.e. it won't allow larger than 460).

Examples:

https://github.com/twbs.png

https://github.com/npm.png?size=200

https://github.com/github.png?size=40

Solution 2 - Github Api

https://developer.github.com/v3/users/#get-a-single-user

Use the /users/:user endpoint. Should be under avatar_url in the returned json.

For example, my avatar_url can be found by hitting this url.

##Edit

There is another way I can think of that is kind of roundabout. Since GitHub uses Gravatar, if you know the email associated with the account, do an md5 hash of the lowercase, stripped email address and construct a url like http://www.gravatar.com/avatar/[md5_here].

Solution 3 - Github Api

This is an old post but nobody has proposed Github Search Users API with scope field :

Or using new Graphql API v4 :

{
  search(type: USER, query: "in:email bmartel", first: 1) {
    userCount
    edges {
      node {
        ... on User {
          avatarUrl
        }
      }
    }
  }
}

Solution 4 - Github Api

Using GraphQL API v4, this will work too

Query (for username)-

{
    user(login: "username") {
        avatarUrl
    }
}

Response -

{
    "data": {
        "user": {
            "avatarUrl": "https://avatars1.githubusercontent.com/u/..."
        }
    }
}

Solution 5 - Github Api

GitHub avatar can be accessed through https://avatars.githubusercontent.com/u/YOUR_USER_ID

Optionally, you can modify the size at the end like so https://avatars.githubusercontent.com/u/YOUR_USER_ID?s=460

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFez VrastaView Question on Stackoverflow
Solution 1 - Github ApiPaulView Answer on Stackoverflow
Solution 2 - Github ApiphotoionizedView Answer on Stackoverflow
Solution 3 - Github ApiBertrand MartelView Answer on Stackoverflow
Solution 4 - Github ApiSamkit JainView Answer on Stackoverflow
Solution 5 - Github ApiAjCodezView Answer on Stackoverflow