【问题标题】:Github api returns bad credentials even with oauth token即使使用 oauth 令牌,Github api 也会返回错误的凭据
【发布时间】:2020-05-19 05:21:40
【问题描述】:

更新:即使是这样的请求也会获得错误的凭据 ==>

curl -H "Authorization: token [token]" https://api.github.com

================

我在我的 iOS 应用程序中这样请求 GitHub OAuth:

URL: https://github.com/login/oauth/authorize,
params: client_id: ****, redirect_uri: app_url, scope: "repo", state: "0"

从 Safari 重定向后,我得到一个代码。我需要访问两件事:

  1. 用户数据,如电子邮件等。同时更新用户数据。
  2. 公共和私有存储库中的存储库和提交列表。

我提出以下要求:

网址:https://api.github.com/user,获取并打补丁 标头:授权:令牌 [代码]

URL: https://api.github.com/repos/:username/:repoName
Header: Authorization: token [code]

但不幸的是,我收到以下错误:

401, Unauthorized
{
    "message": "Bad credentials",
    "documentation_url": "https://developer.github.com/v3"
}

问题是什么,我该如何解决?

【问题讨论】:

    标签: github oauth github-api github-oauth


    【解决方案1】:

    正如在此 blob(不是主要文档)中所说,您必须通过此 api 与不记名令牌交换令牌(这是临时的):

    the main api

    以下是其他人的文档: Github blob documentation

    【讨论】:

      【解决方案2】:

      以下 curl 命令有效: curl -u your_git_name:your_personal_access_token https://api.github.com/user

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-07
        • 2020-05-15
        • 2017-05-08
        • 2018-11-08
        • 2019-01-04
        • 2018-08-03
        • 2016-01-09
        • 2021-03-24
        相关资源
        最近更新 更多