首页 > 解决方案 > 即使使用 oauth 令牌,Github api 也会返回错误的凭据

问题描述

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

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. 公共和私有存储库中的存储库和提交列表。

我提出以下要求:

URL: https://api.github.com/user , 获取并打补丁 Header: Authorization: token [code]

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

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

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

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

标签: githuboauthgithub-apigithub-oauth

解决方案


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

主要的api

这是其他人的文档: Github blob 文档


推荐阅读