Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does one upload a photo to twitter with the API function POST statuses/update_with_media
    primarykey
    data
    text
    <p><strong>[Update 2011-09-21 11:19]</strong> I've fixed one problem that was causing a problem and that was GMT/GMT+2 My local time is at GMT+2, and twitter is using GMT+0/UTC. This was causing a timestamp out of bounds error.</p> <p>I've now fixed that problem and now facing the next problem: string(96) "{"request":"/1/statuses/update_with_media.json","error":"Could not authenticate with OAuth."}"</p> <p>This is the request header generated through Themattharris PHP library (using curl):</p> <pre><code> ["request_header"]=&gt; string(587) "POST /1/statuses/update_with_media.json HTTP/1.1 User-Agent: themattharris' HTTP Client Host: upload.twitter.com Accept: */* Authorization: OAuth oauth_consumer_key="L9AWIB6jvxm3Req1XWHxJA", oauth_nonce="9e41eea04e2dcc2b67784b35c27d8740", oauth_signature="N2Y4YzYwMDg1YjBmZTA1NDgwNDdjOGY3MDI4YjdiNWE3M2E5ZTA5YQ%3D%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1316596483", oauth_token="373846001-bJYH4C47vk34yfIH3XbpvvfZjd2JrIX9OlO5MyO2", oauth_version="1.0" Content-Length: 10024 Content-Type: multipart/form-data; boundary=----------------------------3ddd9c41c091 " </code></pre> <p>I am fairly sure that I used the correct secrets (copy-pastaed from the twitter dev pages of my application) There I also generated my private secret token</p> <p><strong>[Update 2011-09-21 ~10:45]</strong> So I've got around using a PHP lib (rewritten to C++/CLI) and my C++ lib now produces the exact same results as the PHP Lib. (The Authorization header string).</p> <p>For some reason I keep getting a status:(401) Unauthorized. I am using System.Net.WebClient to make the request. And using UploadValues to, well upload the values.</p> <p>If I use something like UploadData or using WebRequest instead of WebClient I get a Status:(500) Internal Server error.</p> <p>I can provide all the strings and headers that I generate if needed (but I of course won't give out the secrets)</p> <p>This is for example what my basestring and authorization string look like:</p> <blockquote> <p>BaseString: POST&amp;https%3A%2F%2Fupload.twitter.com%2F1%2Fstatuses%2Fupdate_with_media.json&amp;oauth_consumer_key%3DL9AWIB6jvxm3Req1XWHxJA%26oauth_nonce%3Ddb0ca1f6c926c1d3ae0d9cbb2c349ae2%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1316538778%26oauth_token%3D373846001-bJYH4C47vk34yfIH3XbpvvfZjd2JrIX9OlO5MyO2%26oauth_version%3D1.0</p> <p>Authorization: OAuth oauth_consumer_key="L9AWIB6jvxm3Req1XWHxJA", oauth_nonce="db0ca1f6c926c1d3ae0d9cbb2c349ae2", oauth_signature="OGI4ZDVkYjZjNjA3YWMyZGYxNWYzZDBhNDE0ODcwMzRkMDE4OWZiYQ%3D%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1316538778", oauth_token="373846001-bJYH4C47vk34yfIH3XbpvvfZjd2JrIX9OlO5MyO2", oauth_version="1.0"</p> </blockquote> <hr> <p>Below is the old text, which is not valid any more.</p> <hr> <p>I might be a simple question, but I just can't figure this out. I am using <a href="http://www.twitterizer.net/" rel="nofollow">Twitterizer</a> to get me the required secret tokens. This library also provides a way to update your twitter with a new tweet, but it does not support the new update_with_media call.</p> <p>I've tried several ways, one way by using WebRequest and the other way by using WebClient (pseudo-C#-code):</p> <pre><code>string URL = "https://upload.twitter.com/1/statuses/update_with_media.json?oauth_consumer_secret=[mysecretgoeshere]&amp;oauth_token_secret=[usersecretgoeshere]"; System.Net.ServicePointManager.Expect100Continue = false; Byte[] fileData = File.ReadAllBytes(pathToFile); #if useWebRequest string postString = "status={statusgoeshere}&amp;image[]={Encoding.ASCII.GetString(fileData)}"; Byte[] postData = Encoding.ASCII.GetBytes(postString); WebRequest wr = WebRequest.Create(URL); wr.Method = "POST"; wr.ContentType = "multipart/form-data"; //as required by twitter API wr.ContentLength = postData.Length; IO.Stream rqstream = wr.GetRequestStream(); rqstream.Write(postData,0,postData.Length); rqstream.Close(); wr.GetResponse(); //returns status 500 internal server error #else WebClient client = new WebClient(); NameValueCollection postData = new NameValueCollection(); postData.Add("status", "{statusgoeshere}"); postData.add("media[]", Encoding.ASCII.GetString(fileData)); client.UploadValues(URL, "POST", postData); //returns status 401 not authorized #endif </code></pre> <p>I wonder what I am doing wrong (if I am doing something wrong that is). Both ways seem valid in my eyes, but I might be missing some things.</p> <p>Edit1: I've noticed I am passing the oath parameters in the wrong way, will try and update that part.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload