简体   繁体   English

Twitter:仅限应用程序的身份验证错误Access-Control-Allow-Origin不允许使用Origin null

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

i am trying to send a application only authentication request to twitter to get the access_token .i write a javascript code 我正在尝试向twitter发送仅应用程序身份验证请求以获取access_token .i编写javascript代码

function getTwitterAuthorizeTokens() { return {oauth_token: "abcdefg", oauth_token_secret: "asdfasdfasfdasdf"}; 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 我关注此链接https://dev.twitter.com/docs/auth/application-only-auth

when i host it using node.js .it is giving me error 当我使用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

You are sending a cross domain ajax request from your browser, which is mostly not allowed for security reasons. 您正在从浏览器发送跨域ajax请求,出于安全原因,这一请求通常是不允许的。 You must send the request from your server instead of client's browser. 您必须从服务器而不是客户端的浏览器发送请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对于从 file:// URL 运行的应用程序发出的请求,“Access-Control-Allow-Origin 不允许使用 Origin null”错误 - “Origin null is not allowed by Access-Control-Allow-Origin” error for request made by application running from a file:// URL Access-Control-Allow-Origin不允许使用Origin null(同步,无jQuery) - Origin null is not allowed by Access-Control-Allow-Origin (Synchronous, no jQuery) 无法与jsonp配合使用的Access-Control-Allow-Origin不允许使用Origin null - Origin null is not allowed by Access-Control-Allow-Origin not working with jsonp Access-Control-Allow-Origin不允许使用Chrome Origin null - Chrome Origin null is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin不允许使用null - Origin null is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin 不允许来源 null - Origin null is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin不允许使用原点null - Origin null is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin 不允许 Origin - Origin is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin不允许使用Origin? - Origin is not allowed by Access-Control-Allow-Origin? Access-Control-Allow-Origin不允许起源 - Origin is not allowed by Access-Control-Allow-Origin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM