如何在Postman中使用GitHub API

3
我想通过 Postman 使用 Github API 在我的 Github 帐户上创建一个文件。
Github API 用于在 Github 帐户上创建文件:
PUT /repos/:owner/:repo/contents/:path 

有人能告诉我如何在Postman中使用这个API吗?
我有一个公共的GitHub帐户:https://github.com/ritzygithub/myfirstRepo 在Postman的头部中我设置了...
Authorization type to OAuth 2
Authorization : token <token>
PUT request with url: https://api.github.com/repos/ritzygithub/myfirstRepo/

请问你能帮我翻译这个吗?

enter image description here

谢谢。

1个回答

4

我刚刚找到了解决方法,现在把答案发布在这里,以便如果有人遇到同样的问题,可以帮助他们。

在 Postman 中,将请求设置为 PUT 请求,并使用以下 URL。

https://api.github.com/repos/YourUsername/YourRepo/contents/file.txt

添加正文:
{
  "message": "my commit message",
  "committer": {
    "name": "My name",
    "email": "my email"
  },
  "content": "base64encoded"
}

头部信息: 内容类型: application/json 授权: token

请参考以下截图: enter image description here

希望这能帮到您。 谢谢


1
只是要补充一下,GitHub 已经弃用了基于凭证的身份验证,现在您需要生成一个令牌,通过访问您的帐户并访问开发人员设置来完成。 - Mirza Sisic

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接