我收到“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");
})
}
}
答案 0 :(得分:0)
根据文件: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上运行服务器。