Twitter :Application-only authentication error Origin null is not allowed by Access-Control-Allow-Origin


#1

i am trying to send a application only authentication request to twitter to get the access_token .i write a javascript code

function getTwitterAuthorizeTokens() { return {oauth_token: "abcdefg", oauth_token_secret: "asdfasdfasfdasdf"}; }

// 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"); } });

when this script is loaded .it is giving me error in console

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
how to resolve this error please guideline. i am following this link https://dev.twitter.com/docs/auth/application-only-auth


#2

Same here, someone please help.


#3

Same here


#4

No answers yet ? Anyone… ?