【发布时间】:2018-02-15 11:35:21
【问题描述】:
在关注 GitHub API 上的文档后,我一直在提交评论以获取要点,以下代码总是返回 404,并且在 Postman 中也进行了相同的调用。
我的JavaScript代码如下:
const config = {
method: 'POST',
headers: {
'Authorization': credentials.authorizationHeader,
'Content-Type': 'application/vnd.github.v3.text+json'
},
body: { "body": JSON.stringify(comment) }
};
fetch(`https://api.github.com/gists/${gistId}/comments/`, config)
.then(res => {
if (res.ok) {
dispatch(getGistDetails(gistId, credentials));
dispatch({ type: SUBMIT_COMMENT_SUCCESS });
} else {
ToastAndroid.show('An error ocurred, please try again.', ToastAndroid.SHORT);
console.log(res);
dispatch({ type: SUBMIT_COMMENT_FAIL });
}
})
.catch(err => console.log(err));
我通过 OAuth 获得的凭据:
accessToken: "redacted"
authorizationHeader:"bearer redacted"
clientID:"redacted"
idToken:null
scopes:"gist"
type:"bearer"
我尝试将authorizationHeader 更改为token <oauth_token,但仍然没有成功。
提前致谢。
【问题讨论】:
-
404 是
Not Found错误代码。您使用的url很可能指向一个不存在的gist -
gist存在。根据 API 的文档,404通常表示403,但我的凭据(据说)是正确的。 -
供参考,这是
gist我要评论的:https://gist.github.com/desktp/8e376d6cd8d671e14c735d051eff7140 -
看起来您在上面的查询中有一些隐藏的 UTF 字符...
标签: javascript api github gist