首页 文章

Twitter API错误:'internal server error'

提问于
浏览
0

我尝试使用Twitter API使用Javascript发布推文 . 详情如下

Base String

POST&HTTP%3A%2F%2Fapi.twitter.com%2F1%2Fstatuses%2Fupdate.json&oauth_consumer_key%3DXXXXXXXXXXX%26oauth_nonce%3D9acc2f75c97622d1d2b4c4fb4124632b1273b0e0%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1305227053%26oauth_token%3D159970118-XXXXXXXXXXXXXXXXXXXXXXX%26oauth_version%3D1.0%26status %3DHello

Header

的OAuth oauth_nonce = “9acc2f75c97622d1d2b4c4fb4124632b1273b0e0”,oauth_signature_method = “HMAC-SHA1”,oauth_timestamp = “1305227053”,oauth_consumer_key = “XXXXXXXXXXXXXXXXX”,组oauth_token = “159970118-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”,oauth_signature = “IWuyoPJBrfY03Hg5QJhDRtPoaDs%3D”,oauth_version = “1.0”

我使用POST方法与body“status = Hello”

但我得到一个内部服务器错误..我身上有任何错误吗?提前致谢 .

使用的Javascript代码

h是上面给出的 Headers

鸣叫=“你好”

encodeURLall是用户定义的,适用于所有其他场合 .

var xhr = new XMLHttpRequest();
xhr.open("POST","http://api.twitter.com/1/statuses/update.json", false);
xhr.setRequestHeader("Authorization",h);

xhr.onreadystatechange = function() {

    if (xhr.readyState == 4 )
    {
        console.log("STATUS="+xhr.status);  
        console.log("RESPONSE="+xhr.responseText);  
    }
}

xhr.send("status="+encodeURLall(tweet));

}

1 回答

  • 0

    由于Same origin policy,您无法使用XMLHttpRequest访问Twitter的网站 . 使用JSONP或服务器端代理(调用您自己的服务器将您的请求重定向到Twitter) .

    BTW, encodeURLall() 做什么?你不应该只使用 encodeURIComponent 吗?


    Update: 引用Google

    常规网页可以使用XMLHttpRequest对象从远程服务器发送和接收数据,但它们受到相同原始策略的限制 . 扩展不是那么有限 . 扩展可以与其来源之外的远程服务器通信,只要它首先请求跨源权限即可 .

    请阅读那里,看看你应该改变哪些设置才能使这项工作 .

相关问题