我收到“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");
})
}
}