簡體   English   中英

GitHub API-評論Gist返回404

[英]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 ,但仍然沒有成功。

提前致謝。

看起來您的GIST ID中有一些甚至不可見的非標准字符,我什至無法使您的鏈接正常工作(或者它是私有的?)

您的查詢

原來我是過於復雜,因為通過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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM