开发者

Problem with twitter API: cannot update status

I am trying to create Google Chrome extension that will send interesting links to twitter. But, I am unable to connect to the Twitter. The server gets my request, but the response is always the same: "You do not have permission to access /1/statuses/update.json on this server (403 Forbidden)." I am using Wireshark to inspect Http responses. Here is the code of the function i am using:

function setStatus(msg) {
var status = "status="+msg;
var client = new XMLHttpRequest();
client.open("POST","http://api.twitter.com/1/statuses/update.json");
client.setRequestHeader("Authorization", "Basic <user credentials>");
client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
client.onreadystatechange = function(){
        if(client.readyState ==4){
            //whatever
        }
    }
client.send(status);

Am I doing something wrong? I am using Basic Auth. I use this tool to do the encod开发者_JS百科ing, and just put the result instead of "user credentials" part. Also, can someone give me an example of OAuth?


I have already posted what was the problem, but for some reason, that post is missing. Nevermind, here is what happened: The code sample I gave in the first post was correct, but I made a mistake in the manifest file. The manifest file contains the "permissions" section - I needed to list all of the links that extension was going to use. I forgot to list "http://api.twitter.com" and that was the problem. When I added that link, everything started working. Thanks for suggestions and responses.


You should also be able to do:

client.open("POST","https://screen_name:password@api.twitter.com/1/statuses/update.json");

and not worry about changing the request headers.


Use /account/verify_credentials to check your authentification first, you might did some mistakes with the encoding, or the password is simply wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜