89

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?

5 Answers 5

209

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

6
18

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].

8
  • Thanks but I need directly the image, would be not enough lightweight parse the json...
    – Fez Vrasta
    Apr 8, 2014 at 9:12
  • additionally, I've not the github username, I've just user display name (Foo Bar, not foobar) and the email (info fetched from a commit detail)
    – Fez Vrasta
    Apr 8, 2014 at 9:18
  • Off the top of my head I don't believe there will be any fully accurate way of getting a user's github picture then--as git commits can have any email address attached to them, it doesn't have to map to a github user. That being said, I believe my edit about MD5 hashes and gravatar might be your best bet. Apr 8, 2014 at 9:21
  • I already check that the repository is a GitHub repo and it's good think users use only correct emails for their commits. I can't use Gravatars because lot of users don't use gravatars on GitHub (gravatars are already implemented in my code)
    – Fez Vrasta
    Apr 8, 2014 at 9:24
  • 1
    Oh, one last thing regarding Gravatar generation, looks like GitHub uses a default size of 460, so you can pass in ?size=460 at the end of your gravatar url and it will give you the same thing as the GitHub url from their api. Apr 8, 2014 at 9:25
3

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
        }
      }
    }
  }
}
2

Using GraphQL API v4, this will work too

Query (for username)-

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

Response -

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

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

2
  • It looks like YOUR_USER_ID has to be the numeric id, not the github name. So this isn't really answering the question I'm afraid.
    – broofa
    Oct 15, 2017 at 11:34
  • 1
    True story With email, not sure if it's possible. With github username: github.com/USERNAME.png
    – AjCodez
    Oct 19, 2017 at 17:21

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.