简体   繁体   中英

How to do a POST update request to twitter API?

I've been trying for a while to do a POST request to of twitter TwitterAPI: update_with_media , but apparently I am not authenticating correctly since I am getting a "Bad Authentication" error...

I am using this windows8 sample to do the authentication for me: Web Authentication

It gives me the token correctly (no error exit status, at least...), so what am I doing wrong?

I've been looking at twitter's documentation and I didn't found how to "bind" the oauth token to a request, like I would do in facebook: graph_url/me/access_token=xxxxx or "access_token" as a POST param. Is that what is missing?

The request code looks like this:

    var formData = new FormData();
    formData.append("status", "stuff");
    formData.append("media[]", arrImgs);
    WinJS.xhr({type: "POST", url: "https://upload.twitter.com/1/statuses/update_with_media.json", data: formData})

Just from the link you provided. You should add the token as a Header:

 function sendPostRequest(url, authzheader) { 
    try { 
        var request = new XMLHttpRequest(); 
        request.open("POST", url, false); 
        request.setRequestHeader("Authorization", authzheader); 
        request.send(null); 
        return request.responseText; 
    } catch (err) { 
        WinJS.log("Error sending request: " + err, "Web Authentication SDK Sample", "error");             
    } 
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM