通过Github用户ID

时间:2016-03-13 15:42:04

标签: github

有没有一种很好的方法可以在github中获取ID的用户名和信息?

使用ID我目前可以获取头像,但不能获取任何其他用户信息。

例如: https://avatars.githubusercontent.com/u/2015

我查了一个类似的问题:Get github username by id

但建议的答案似乎不再适用。

https://api.github.com/user/:2014什么都不返回。

2 个答案:

答案 0 :(得分:2)

你的问题很容易。你错过了一些事实。我正在为你清理这些,

  • 您必须检查GITHUB API V3 - 了解这些api的确如何运作。这对未来的项目很有帮助。

  • 并请https://api.github.com/user/:2014使用稍微错误的方式。你看,你必须以https://api.github.com/user/2014这种方式使用它。在我的情况下它提供,

    { "login": "lee", "id": 2014, "avatar_url": "https://avatars.githubusercontent.com/u/2014?v=3", "gravatar_id": "", "url": "https://api.github.com/users/lee", "html_url": "https://github.com/lee", "followers_url": "https://api.github.com/users/lee/followers", "following_url": "https://api.github.com/users/lee/following{/other_user}", "gists_url": "https://api.github.com/users/lee/gists{/gist_id}", "starred_url": "https://api.github.com/users/lee/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/lee/subscriptions", "organizations_url": "https://api.github.com/users/lee/orgs", "repos_url": "https://api.github.com/users/lee/repos", "events_url": "https://api.github.com/users/lee/events{/privacy}", "received_events_url": "https://api.github.com/users/lee/received_events", "type": "User", "site_admin": false, "name": null, "company": null, "blog": null, "location": "New York, NY", "email": null, "hireable": null, "bio": null, "public_repos": 6, "public_gists": 7, "followers": 16, "following": 7, "created_at": "2008-03-03T14:23:14Z", "updated_at": "2016-02-26T22:34:45Z" }

所以,我认为这将解决问题,祝你今日美好。 :)

答案 1 :(得分:0)

对于希望使用 GitHub v4 GraphQL API 执行此操作的任何人,您的操作方法如下:

{
  node (id: "INSERT USERID") {
    ... on User {
      id
      login
    }
  }
}

... on User 允许您查找特定于 User 对象的属性,因为 Node 可以是任意数量的事物(例如用户、存储库、提交)。有关详细信息,请参阅 official answer by GitHub on their forum