I'm trying to post a Twitter status update and I just can't get it working.
var consumer = new TwitterConsumer(); // WebConsumer implementation
var httpClient = new HttpClient(consumer.CreateAuthorizingHandler("THE_TOKEN", new HttpClientHandler()));
var content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{"status", "test"}
});
// yes, yes, ugly code, only testing here
var s = httpClient.PostAsync("https://api.twitter.com/1.1/statuses/update.json", content);
var t = s.Result;
var u = t.Content.ReadAsStringAsync().Result; // HTTP 401, response from Twitter is {"errors":[{"message":"Could not authenticate you","code":32}]}
Of course, initially I thought there were some problems with my auth tokens or the OAuth process, but all other things are working fine:
The OAuth authentication seems to work, because I can access other API methods like https://api.twitter.com/1.1/account/settings.json
.
I can even post status updates when submitting the status
via the URI, like POST https://api.twitter.com/1.1/statuses/update.json?status=test
. I only get the error when I try to put the status
in the request body.
According to Google a lot of people have similar problems, unfortunately the suggested solutions (like double-checking the url-encoding or the content
-Request-Header) do not work for me (the request looks as it should in Fiddler).
status
parameter to the URL instead of to the body. So I used a POST request, but a GET parameter - I'll update my question accordingly. Apologies for the mix-up. – Intimidate