如何在Postman中使用GitHub API [英] How to use GitHub API in Postman

查看:355
本文介绍了如何在Postman中使用GitHub API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拿一份邮递员的公开要点清单。
我可以在命令行中执行 curl https://api.github.com/gists/public ,效果很好。

I would like to get a list of public gists in Postman. I can do curl https://api.github.com/gists/public in my command line which works fine.

但是我没有设法在Postman中找到相同的方法。

However I did not manage to find out how to do the same in Postman.

我尝试在 https://api.github.com/gists/public 发出GET请求返回以下对象:

I tried to make a GET request at https://api.github.com/gists/public which returned the following object:

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

我发现从命令行发出请求时,不需要进行身份验证会令人困惑,但是当我想从Postman进行基本相同的操作时,它将引发错误。

I find it confusing to not to be required to authenticate when making the request from command line but when I would like to do basically the same from Postman it throws an error. But ok, I tried to authenticate myself.

我在GitHub上创建了一个OAuth应用程序,因此我收到了一个Client ID和Client Secret。

I have created an OAuth application in my GitHub so I recieved a Client ID and Client Secret.

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

I have tried to pass these to my requests as query params / header information / and also as part of the body without any success.

我还尝试过使用Web应用程序流程( https://developer.github .com / v3 / oauth /#web-application-flow ),并尝试通过向 https://api.github.com/authorizations ,其中包含我的用户ID和用户密码( https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization ),则返回

I also have tried to use the web application flow (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), which returned

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

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

Now I am super confused about what should generate my token, and where should I pass it to. All I want is some public information (public gists) in Postman, the same as in command line.

推荐答案

使用标头方法,您应该可以将授权:令牌OAUTH-TOKEN直接放入标题部分下的键输入中。

Using the header method, you should be able to put "Authorization: token OAUTH-TOKEN" directly into the key input under the Headers section.

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

Obviously replace OAUTH-TOKEN with your actual token.

编辑:以上是正确的,但我发现它并不明显。该图显示了要执行的操作,(a)在关键字段中,输入授权,(b)在值字段中,输入令牌。

The above is correct, but I found it non obvious. The image shows what to do, (a) in the key field, put in 'Authorization', (b) in the value field, put in 'token '.

卷曲地看它,它向请求添加 -H Authorization:token<您的令牌在这里> 到请求。

Looking at it in curl, it add -H "Authorization: token <your token here>" to the request, which is what is needed.

邮递员通过Oauth身份验证到github API

这篇关于如何在Postman中使用GitHub API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆