kdi*_*olo 3 javascript api github
我在使用 JavaScript fetch 方法向 GitHub API 发出 POST 请求时遇到问题:
fetch('https://api.github.com/repos/organization/repo/issues?client_id=CLIENT_ID&client_secret=CLIENT_SECRET', {
method: 'post',
body: {
title: 'Title',
body: {body: "body", title: "title"}
}
})
Run Code Online (Sandbox Code Playgroud)
我正在使用通过向 GitHub API 注册应用程序获得的客户端 ID 和客户端密钥:
任何帮助将不胜感激!谢谢!
我猜您需要访问令牌才能访问 Github API。如果您想手动尝试这里是我的建议步骤。我将尝试从第一步开始解释。
注册您的应用程序。
在您的 github 帐户上,转到 settings -> OAuth Applications
获取客户端 ID 和客户端密钥。
索取 Github 代码
现在你有Client ID。转到此网址。
https://github.com/login/oauth/authorize?client_id=b420627027b59e773f4f&scope=user:email,repo
请定义您自己的client_id和scope.
获取 Github 代码
还记得注册时输入的授权回调地址吗?转到上面的链接后,您应该已重定向到您的回调 URL,并将代码作为参数。
例如 http://localhost:8080/github/callback?code=ada5003057740988d8b1
询问并获取访问令牌
现在,你需要做的http请求后用Client ID,Client Secret和Code你有作为参数。
要求
POST https://github.com/login/oauth/access_token?client_id=a989cd9e8f0137ca6c29&client_secret=307d18600457b8d9eec1efeccee79e34c603c54b&code=ada5003057740988d8b1
回复
access_token=e72e16c7e42f292c6912e7710c838347ae178b4a&token_type=bearer
将问题发布到 Github
现在您access token可以使用它来访问 Github API。
fetch('https://api.github.com/repos/organization/repo/issues?access_token=e72e16c7e42f292c6912e7710c838347ae178b4a', {
method: 'post',
body: {
title: 'Title',
body: {body: "body", title: "title"}
}
})Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3805 次 |
| 最近记录: |