title: Twitter :Application-only authentication error Origin null is not allowed by Access-Control-Allow-Origin
body: <p>i am trying to send a application only authentication request to twitter to get the access_token .i write a javascript code</p>
  
  <p>function getTwitterAuthorizeTokens() {
          return {oauth_token: "abcdefg", oauth_token_secret: "asdfasdfasfdasdf"};
      }</p>
  
  <pre><code>// 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");
          }
  });
  </code></pre>
  
  <p>when this script is loaded .it is giving me error in console</p>
  
  <pre><code>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
  </code></pre>
  
  <p>how to resolve this error please guideline. i am following this link <a href="https://dev.twitter.com/docs/auth/application-only-auth" rel="nofollow">https://dev.twitter.com/docs/auth/application-only-auth</a></p>
  
  <p>when i host it using node.js .it is giving me error</p>
  
  <pre><code>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
  </code></pre>