Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get github username through primary email

I'm using the PyGithub library to invite new member to the organization. The issue I faced is the next: In the scenario, when I know only users primary email, how can I retrieve his username to proceed invite accordingly? I know it is possible through UI, but can't find the corresponding call through API. Please, assist!

like image 374
million_miles Avatar asked Jul 03 '17 14:07

million_miles


2 Answers

Use github user search api for this . I tried the below one.

https://api.github.com/search/[email protected]

Key name login is the username here. response:

{
  "total_count": 1,
  "incomplete_results": false,
  "items": [
    {
      "login": "arpit1997",
      "id": 10682054,
      "avatar_url": "https://avatars1.githubusercontent.com/u/10682054?v=3",
      "gravatar_id": "",
      "url": "https://api.github.com/users/arpit1997",
      "html_url": "https://github.com/arpit1997",
      "followers_url": "https://api.github.com/users/arpit1997/followers",
      "following_url": "https://api.github.com/users/arpit1997/following{/other_user}",
      "gists_url": "https://api.github.com/users/arpit1997/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/arpit1997/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/arpit1997/subscriptions",
      "organizations_url": "https://api.github.com/users/arpit1997/orgs",
      "repos_url": "https://api.github.com/users/arpit1997/repos",
      "events_url": "https://api.github.com/users/arpit1997/events{/privacy}",
      "received_events_url": "https://api.github.com/users/arpit1997/received_events",
      "type": "User",
      "site_admin": false,
      "score": 52.297474
    }
  ]
}
like image 198
Arpit Solanki Avatar answered Sep 18 '22 10:09

Arpit Solanki


PyGithub API

Refer to search_users.

search_users(query, sort=NotSet, order=NotSet, **qualifiers)

  • query – string
  • sort – string (‘followers’, ‘repositories’, ‘joined’)
  • order – string (‘asc’, ‘desc’)
  • qualifiers – keyword dict query qualifiers

For example,

g = github.Github("USERNAME", "PASSWORD")
users = g.search_users("franky in:email")
for user in users:
    print(user.login)  # print the selected users' username.

GitHub API

According to GitHub API Search users, you can specify only searching by public email using keyword in.

For example,

https://api.github.com/search/users?q=franky+in:email

Then, you'll only get users with "franky" in there emails.

like image 20
YLJ Avatar answered Sep 20 '22 10:09

YLJ