Redirect GitHub ID to Username
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.
JAVASCRIPT<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.