8

我正在使用 PyGithub 库邀请新成员加入组织。我面临的问题是下一个:在这种情况下,当我只知道用户的主电子邮件时,我如何检索他的用户名以进行相应的邀请?我知道通过 UI 可以,但是通过 API 找不到对应的调用。请协助!

4

3 回答 3

12

为此使用 github用户搜索 api。我尝试了下面的一个。

https://api.github.com/search/users?q=solankiarpit1997@gmail.com

键名login是这里的用户名。回复:

{
  "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
    }
  ]
}
于 2017-07-03T14:47:20.510 回答
8

PyGithub API

请参阅search_users

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

  • 请求参数
  • 排序 - 字符串('followers'、'repositories'、'joined')
  • 顺序 - 字符串('asc','desc')
  • qualifiers – 关键字 dict 查询限定符

例如,

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

根据 GitHub API Search 用户,您可以使用关键字指定仅通过公共电子邮件进行搜索in

例如,

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

然后,您只会在电子邮件中收到带有“坦率”字样的用户。

于 2017-07-03T15:03:21.287 回答
0

我在 github 上有公共电子邮件地址,但无法让我的用户名通过电子邮件地址

-bash-4.2$ curl -i -s  https://api.github.com/search/users?q=kamu.raju@gmail.com
    HTTP/1.1 200 OK
    Server: GitHub.com
    Date: Sun, 09 May 2021 15:00:13 GMT
    Content-Type: application/json; charset=utf-8
    Cache-Control: no-cache
    Vary: Accept, Accept-Encoding, Accept, X-Requested-With
    X-GitHub-Media-Type: github.v3; format=json
    Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X- 
    RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X- 
    RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub- 
    Media-Type, Deprecation, Sunset
    Access-Control-Allow-Origin: *
    Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
    X-Frame-Options: deny
    X-Content-Type-Options: nosniff
    X-XSS-Protection: 0
    Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
    Content-Security-Policy: default-src 'none'
    X-RateLimit-Limit: 10
    X-RateLimit-Remaining: 8
    X-RateLimit-Reset: 1620572473
    X-RateLimit-Resource: search
    X-RateLimit-Used: 2
    Accept-Ranges: bytes
    Content-Length: 73
    X-GitHub-Request-Id: 8CAA:5135:2353C0C:3D598CC:6097F908

    {
    "total_count": 0,
    "incomplete_results": false,
    "items": [

     ]
     }

在此处输入图像描述

于 2021-05-09T15:01:53.113 回答