[英]GitHub API - Comment on Gist returns 404
在遵循了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
,但仍然沒有成功。
提前致謝。
原來我是過於復雜,因為通過API獲得一個要點的詳細信息網還你一個comments_url
用正確的URL字段,所以無需拼接字符串,落入由下面@Zilvinas所提的一個很奇怪的問題。 此外,身體的輕微調整
const body = { body: comment }
const config = {
method: 'POST',
headers: {
'Authorization': credentials.authorizationHeader,
'Content-Type': 'application/vnd.github.v3.text+json'
},
body: JSON.stringify(body)
};
修復了我在Problems parsing JSON
錯誤時遇到的后續Problems parsing JSON
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.