Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get github username by id

Using this link I can see that my (tonylampada) id on github is 218821 https://api.github.com/users/tonylampada

How could I do the opposite? Given the user id = 218821, what's the username?


Update

Answering nulltoken here because it's a long story and it won't fit in a comment.

FreedomSponsors is a django application that uses django-social-auth to enable login with Github (and others). (You should check it out, btw, please see the about page in the blog :-) Django-social-auth has a configuration flag that allows the application to store the github username on the database. A few days ago I deployed a new version of FS with github login enabled, but with "storeGithubUsername" set to false.

A few users registered their github accounts, and now the database has their github ids, but not their usernames.

You can se in my profile that I have github as a "connected account" but there's no link to my github page.

I need it to make the link point to https://github.com/tonylampada

I'm ready to deploy a new version that fixes this, by setting the "storeGithubUsername" (that's not what it is called, I'm just simplifying here) to true. But I'd like to patch the database with the already github-registered users. I have their github ids, but not their github usernames.

like image 416
Tony Lâmpada Avatar asked Aug 15 '12 20:08

Tony Lâmpada


People also ask

How do I find my GitHub username?

GitHub Desktop usersIn the File menu, click Options. In the Options window, verify the following: To view your GitHub username, click Accounts.

Is GitHub ID same as username?

GitHub users can change their username - but their ID stays the same.

How do I list users on GitHub?

To get the list of random users, you have to make a request to the /user endpoint, and to get the details of a specific user, you make a request to the /user/{username} endpoint.

Is GitHub username unique?

Since you can use Git outside of GitHub, those two usernames do not have to be the same. Also, the GitHub username must be unique, but nothing forces uniqueness of Git usernames.

How do I Find my GitHub username and email?

In the GitHub Desktop menu, click Preferences. To view your GitHub username, click Accounts. To view your Git email, click Git. Note that this email is not guaranteed to be your primary GitHub email. In the File menu, click Options. To view your GitHub username, click Accounts.

Is my Git username the same as my GitHub username?

The Git username is not the same as your GitHub username. You can change the name that is associated with your Git commits using the git config command. The new name you set will be visible in any future commits you push to GitHub from the command line. If you'd like to keep your real name private, you can use any text as your Git username.

How to set Git username in Bash?

Setting your Git username for a single repository Open Terminal Terminal Git Bash. Change the current working directory to the local repository where you want to configure the name that is associated... Set a Git username: $ git config user.name "Mona Lisa" Confirm that you have set the Git username ...

How do I find a specific commit in GitHub?

In our example, we are looking for commits by Linus (his GitHub user name is torvalds). Once you locate a commit, you can click the commit ID on the right hand side to view the actual commit. The commit view is not very interesting to us, however this is where the real trick comes in.


1 Answers

We need to do this on Gitter to deal with the situation where a user has changed their username on GitHub and we get a 404 response when querying their old username.

Here's an undocumented endpoint, so use as your own peril, but it does work for now.

Use the endpoint: https://api.github.com/user/:id, where :id is the ID of the user.

Similar endpoints exist for repos and orgs, at https://api.github.com/repositories/:id and https://api.github.com/organizations/:id respectively.

Note that the new repository redirects preview API only supports repositories, not renamed users or organizations. In fact, the HTTP 301 redirect actually points to https://api.github.com/repositories/:id, so there's a good chance that these "ID" endpoints may in fact become official soon.

like image 147
Andrew Newdigate Avatar answered Oct 26 '22 22:10

Andrew Newdigate