GitHub API - 评论 Gist returns 404

GitHub API - Comment on Gist returns 404

在遵循 GitHub 的 API 上的文档之后,我被困在为要点提交评论时,以下代码总是 returns 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,但仍然没有成功。

提前致谢。

看起来你的 GIST ID 中有一些不可见的非标准字符,我什至无法让你的 link 工作(或者它是私有的?)

事实证明我过于复杂了,因为通过 API 获取要点的详细信息也会为您提供一个具有正确 url 的 comments_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 错误。