[Update 2011-09-21 11:19] 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.
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."}"
This is the request header generated through Themattharris PHP library (using curl):
["request_header"]=>
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
"
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
[Update 2011-09-21 ~10:45] 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).
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.
If I use something like UploadData or using WebRequest instead of WebClient I get a Status:(500) Internal Server error.
I can provide all the strings and headers that I generate if needed (but I of course won't give out the secrets)
This is for example what my basestring and authorization string look like:
BaseString: POST&https%3A%2F%2Fupload.twitter.com%2F1%2Fstatuses%2Fupdate_with_media.json&oauth_consumer_key%3DL9AWIB6jvxm3Req1XWHxJA%26oauth_nonce%3Ddb0ca1f6c926c1d3ae0d9cbb2c349ae2%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1316538778%26oauth_token%3D373846001-bJYH4C47vk34yfIH3XbpvvfZjd2JrIX9OlO5MyO2%26oauth_version%3D1.0
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"
Below is the old text, which is not valid any more.
I might be a simple question, but I just can't figure this out. I am using Twitterizer 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.
I've tried several ways, one way by using WebRequest and the other way by using WebClient (pseudo-C#-code):
string URL = "https://upload.twitter.com/1/statuses/update_with_media.json?oauth_consumer_secret=[mysecretgoeshere]&oauth_token_secret=[usersecretgoeshere]";
System.Net.ServicePointManager.Expect100Continue = false;
Byte[] fileData = File.ReadAllBytes(pathToFile);
#if useWebRequest
string postString = "status={statusgoeshere}&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
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.
Edit1: I've noticed I am passing the oath parameters in the wrong way, will try and update that part.