繁体   English   中英

github API的POST请求错误

[英]POST request error with github API

我收到“ Access-Control-Allow-Origin不允许的”错误。 我应该如何使用API​​? 我得到了代码,但是令牌的POST请求失败

var gist = {

clientId: 'clientId',
clientSecret: 'clientSecret',
authUrl: 'https://github.com/login/oauth/authorize',
tokenUrl: 'https://github.com/login/oauth/access_token',

getCode: function() {
    var url = gist.authUrl+'?client_id='+gist.clientId;
    location.href = url;
},
processCode: function() {
    var code = location.search.slice(6);
    var url = gist.tokenUrl;
    $.post(gist.tokenUrl, {
        client_id : gist.clientId,
        client_secret : gist.clientSecret,
        code : code
    }, function(){
        console.log("POST request sent");
    })
        .success(function(data){
            console.log(data);
        })
        .error(function(data){
            console.error("POST request error");
        })
}
}

根据文档: http : //developer.github.com/v3/#cross-origin-resource-sharing

Any domain that is registered as an OAuth Application is accepted.

要注册您的应用程序,请访问: https : //github.com/settings/applications

您需要从与您的应用程序注册相同的域进行发布。 如果您尝试在本地进行测试,则可能需要修改主机文件并在端口80上运行服务器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM