【问题标题】:Github API v3, post issues / authenticationGithub API v3,发布问题/身份验证
【发布时间】:2020-01-26 14:41:38
【问题描述】:

我正在做一个使用 Github API v3 制作看板的项目。 我对 get 方法没有任何问题,但是当涉及到 post 方法时,我得到了 404 响应,从我在文档中读到的内容来看,这似乎是一个身份验证错误。

我正在使用个人令牌进行身份验证,并已通过邮递员成功发布,但是当我尝试通过自己的应用程序发布时,我收到了错误。

如果有人感兴趣,请链接到项目:https://github.com/ericyounger/Kanban-Electron

以下是用于发布到 github 的代码。

下面的代码可能有问题吗?或者可能是与令牌相关的设置?

postIssue(json){

        let packed = this.packPost(json);
        return Axios.post(`https://api.github.com/repos/${this.user}/${this.repo}/issues`, packed);
    }

    packPost(json) {
        return {
            method: "POST",
            headers: {
                "Authorization": `token ${this.tokenAuth}`,
                "Content-Type": "application/json"
            },
            body: JSON.stringify({title: json.title})
        };
    }

这是我收到的:

{message: "Not Found", documentation_url: "https://developer.github.com/v3/issues/#create-an-issue"}
message: "Not Found"
documentation_url: "https://developer.github.com/v3/issues/#create-an-issue"

Console log error message

【问题讨论】:

    标签: api authentication github axios github-api-v3


    【解决方案1】:

    在没有看到任何详细日志的情况下,我的第一次尝试是设置body 不发送正文的字符串表示

    body: {title: json.title}
    

    【讨论】:

    • 实用提示! :-) 但不幸的是,它没有解决它。如果有帮助,我添加了更多错误日志。
    【解决方案2】:

    这成功了:)

        postIssue(json){
            const headers = {
                'Content-Type': 'application/json',
                'Accept': 'application/vnd.github.v3.raw',
                "Authorization": `token ${this.tokenAuth}`,
            };
    
            return Axios.post(`https://api.github.com/repos/${this.user}/${this.repo}/issues`, json , {headers: headers});
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-01
      • 2015-09-08
      • 2021-03-01
      • 2017-07-14
      • 2019-08-24
      • 2011-01-18
      • 2015-03-28
      • 2014-01-25
      相关资源
      最近更新 更多