【问题标题】:Get github username through primary email通过主邮箱获取 github 用户名
【发布时间】:2017-12-06 21:02:42
【问题描述】:

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

【问题讨论】:

  • 不完全确定,但我认为您可以通过电子邮件邀请。
  • @ArpitSolanki 是的,他可以,但是它的 api 函数是什么?

标签: python api github github-api pygithub


【解决方案1】:

我在 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": [

     ]
     }

【讨论】:

    【解决方案2】:

    PyGithub API

    请参阅search_users

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

    • 查询 - 字符串
    • 排序 - 字符串('followers'、'repositories'、'joined')
    • order – 字符串('asc', 'desc')
    • 限定符 - 关键字字典查询限定符

    例如,

    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 users,您可以使用关键字 in 指定仅通过公共电子邮件搜索。

    例如,

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

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

    【讨论】:

      【解决方案3】:

      为此使用 github user search 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
          }
        ]
      }
      

      【讨论】:

      • 如果用户名nateshmbhat1有一个公共邮箱地址nateshmbhatofficial@gmail.com,则只能通过API找到他。我看到了个人资料,我认为该用户的个人资料中有私人电子邮件地址
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 1970-01-01
      • 2019-05-29
      • 2023-04-02
      相关资源
      最近更新 更多