通过id获取github用户名 [英] Get github username by id

查看:417
本文介绍了通过id获取github用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此链接我可以看到,我的(tonylampada)id在github上是218821
https://api.github .com / users / tonylampada



我怎么能做到相反?鉴于用户ID = 218821,用户名是什么?






更新



在这里回答nulltoken是因为这是一个很长的故事,它不适合评论。

FreedomSponsors 是一个django应用程序,它使用django-social-auth来启用Github(和其他)的登录。
(您应该检查一下,顺便说一下,请在博客中查看关于页面 :-)
Django-social-auth有一个配置标志,允许应用程序在数据库上存储github用户名。
几天前,我部署了一个启用了github登录的新版FS,但storeGithubUsername设置为false。

帐户,现在数据库有他们的github标识符,但不是他们的用户名。



你可以在我的个人资料,我有github作为连接帐户,但没有链接到我的github页面。



I需要它将链接指向 https://github.com/tonylampada



我准备部署一个解决此问题的新版本,方法是将storeGithubUsername(不是它所称的,我只是在此简化)设置为true。
但是我想用已经github注册的用户修补数据库。我有他们的github标识符,但不是他们的github用户名。

> Gitter 来处理用户在GitHub上更改用户名的情况,并在查询其旧用户名时收到404响应。



这是一个未公开的终结点,因此可以用作自己的危险,但现在它仍然有效。



使用端点: https://api.github.com/user/:id ,其中:id 是ID的用户。

类似的终端存在于
https://api.github.com/repositories/:id
code>和 https://api.github.com/organizations/:id



请注意,新的存储库重定向预览API 仅支持存储库,而不是重命名的用户或组织。实际上,HTTP 301重定向实际上指向 https://api.github.com/repositories/:id ,所以很有可能这些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.

解决方案

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.

这篇关于通过id获取github用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆