1
내가 자바 스크립트 코드를트위터 : 응용 프로그램 전용 인증 오류 원점는 null에 의해 허용되지 않는 액세스 제어 - 허용 - 원산지
함수를 작성 .I access_token과를 얻기 위해 트위터 만 인증 요청 응용 프로그램을 보내려고 오전 getTwitterAuthorizeTokens() { return {oauth_token : "abcdefg", oauth_token_secret : "asdfasdfasfdasdf"}; 이 스크립트는 .IT를로드
// Get the consumer key and secret
function getTwitterConsumerTokens() {
return {key: "xxxxxxxxxxxxxxxxx", secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"};
}
var s = encodeURIComponent(getTwitterConsumerTokens().key,'RFC 1738');
s += ':'+encodeURIComponent(getTwitterConsumerTokens().secret,'RFC 1738');
$(document).ready(function(){
$.ajax({
type:"POST",
beforeSend: function (request)
{
request.setRequestHeader("Authorization", "Basic "+s);
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
},
url: "https://api.twitter.com/oauth2/token",
data: "grant_type=client_credentials",
processData: false,
success: function(msg) {
alert("successfull");
}
});
}
이 오류가 지침 1하십시오 해결하는 방법 콘솔OPTIONS https://api.twitter.com/oauth2/token 405 (Method Not Allowed) sinon-server-1.7.1.js:573
apply sinon-server-1.7.1.js:573
fakeXhr.(anonymous function) sinon-server-1.7.1.js:592
send jquery.min.js:4
f.extend.ajax jquery.min.js:4
(anonymous function) index.html:143
e.resolveWith jquery.min.js:2
e.extend.ready jquery.min.js:2
c.addEventListener.C jquery.min.js:2
XMLHttpRequest cannot load https://api.twitter.com/oauth2/token. Origin null is not allowed by Access-Control-Allow-Origin. index.html:1
나에게 오류를주고있다. 내가주고있다 .IT Node.js를을 사용하여 호스트 날 때 당신은 주로 보안을 위해 허용되지 않는 브라우저에서 크로스 도메인 아약스 요청을 보내는
Failed to load resource: the server responded with a status of 405 (Method Not Allowed) https://api.twitter.com/oauth2/token?jsonp=success
XMLHttpRequest cannot load https://api.twitter.com/oauth2/token?jsonp=success. Origin http://localhost:8888 is not allowed by Access-Control-Allow-Origin. index.html:1
[encodeURIComponent'] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) 함수에 두 번째 매개 변수가있는 것은 무엇입니까? – c69
파일 시스템이나 서버에서 실행하고 있습니까? – vsr
링크 (https://dev.twitter.com/docs/auth/application-only-auth)에서 RFC 1738을 사용하여 매개 변수를 인코딩해야합니다. 현재 제공되는 것과 동일한 결과를 제공하지만 미래에는 변경 될 것입니다. . –