Twitter API and DotNetOpenAuth & HttpClient: Failed to authenticate you error

I am trying to post a Twitter status update and I just can't get it to work.

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 authentication tokens or the OAuth process, but everything else worked fine:

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 sending status via a URI , such as POST https://api.twitter.com/1.1/statuses/update.json?status=test . I get an error when I try to put status in the request body.

According to Google, many people have similar problems, unfortunately, the proposed solutions (for example, double checking the url encoding or content -Request-Header) do not work for me (the request looks like Fiedler should).

+7
c # twitter dotnetopenauth
source share
1 answer

If you do not solve the answer to your question, this may solve your problem.

I suggest you take a look at linq2twitter . This is a really good C # api for Twitter.

You can either look (open source) at how they implemented the signatures to find a problem with your code, or use it, and not be confused with creating / signing requests and analyzing responses (used in one of my past projects, great works, provides a convenient api).

Look here , for example, update the publication status and be sure to read this section to understand how to correctly configure auth ( TwitterContext ) in your script.

Hope this helps.

+2
source

All Articles