如何在 Postman 中使用 GitHub API

How to use GitHub API in Postman

我想获取 Postman 中的 public 要点列表。 我可以在命令行中执行 curl https://api.github.com/gists/public,效果很好。

但是我没能找到如何在 Postman 中做同样的事情。

我试图在 https://api.github.com/gists/public 发出 GET 请求,它返回了以下内容 object:

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

我发现从命令行发出请求时不需要进行身份验证令人困惑,但是当我想从 Postman 中执行基本相同的操作时,它会抛出错误。但是好吧,我尝试验证自己的身份。

我在我的 GitHub 中创建了一个 OAuth 应用程序,所以我收到了一个客户端 ID 和客户端密码。

我试图将这些作为查询参数/header 信息/以及作为 body 的一部分传递给我的请求,但没有成功。

我也尝试过使用 Web 应用程序流程 (https://developer.github.com/v3/oauth/#web-application-flow), and tried to create a new authorization with sending a POST request to https://api.github.com/authorizations with my User ID and User Secret in it (https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization),结果返回

{
  "message": "Requires authentication",
  "documentation_url": "https://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api"
}

现在我对什么应该生成我的令牌以及我应该将它传递到哪里感到非常困惑。我想要的只是 Postman 中的一些 public 信息(public 要点),与命令行中的相同。

使用header方式,应该可以直接在Headers部分下输入"Authorization: token OAUTH-TOKEN"。

显然用您的实际令牌替换 OAUTH-TOKEN。

编辑:以上是正确的,但我发现它不明显。该图显示了要做什么,(a) 在关键字段中,输入 'Authorization',(b) 在值字段中,输入 'token '.

在curl中查看,它向请求添加-H "Authorization: token <your token here>",这是需要的。

Postman GET to github API with Oauth authentication