Redirect GitHub ID to Username

by @edent | # # # # #

Scratching my own itch here...

GitHub users have a username (mine is @edent) and have a user ID number (mine is #837136).

If you want to redirect a user ID to a username, you can use the little service I've cobbled together:

https://edent.github.io/github_id/#837136

That will take your browser to my GitHub page, using nothing but my ID.

Why?

  • Some login services only give you the GitHub user's ID.
  • GitHub users can change their username - but their ID stays the same.

How?

Inspired by Caius Durling's useful GitHub username to ID service.

Mine is a scrap of JavaScript which uses this undocumented endpoint to get user info.

A screen of JSON code showing my details.

<script type="text/javascript" charset="utf-8">
function get_github_name_for(id) {
    $.getJSON('https://api.github.com/user/' + id + "?callback=?", 
    function(json){
        var github_user_url = json["data"]["html_url"]
        window.location.replace(github_user_url)
        return false
    });
}
$(document).ready(function() {
    if (document.location.hash) {
        var id = document.location.hash.match(/^#(.*?)$/)[1]
        get_github_name_for(id)
    }
});
</script>

Feel free to copy it, or use https://edent.github.io/github_id/#837136 as a handy little webservice.

Support this blog

Enjoyed this blog post? You can say thanks to the author in the following ways:

Donate to charity
Give to charity.
Buy me a birthday present
Amazon Wishlist
Get me a coffee
Donate on Ko-Fi.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.