简体   繁体   English

如何对twitter API发布POST更新请求?

[英]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... 我一直试图对Twitter TwitterAPI:update_with_media做POST请求,但显然我没有正确验证,因为我收到了“错误验证”错误...

I am using this windows8 sample to do the authentication for me: Web Authentication 我正在使用此windows8示例为我进行身份验证: Web身份验证

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. 我一直在查看twitter的文档,我没有找到如何将oauth令牌“绑定”到请求,就像我在facebook中所做的那样:graph_url / me / access_token = xxxxx或“access_token”作为POST参数。 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");             
    } 
} 

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

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