2

I'm using Twitterizer library for posting tweets within a web-site into my twitter account. It works just fine on site, running on my local server (authenticates with OAuth through twitter app and posts a tweet). But when I'm trying to post a tweet on production server, Twitterizer says: "Result = Unauthorized. ErrorMessage = Could not authenticate with OAuth."

I double checked consumer keys, also tried to reset the keys and try again - same result.

Twitter application has read/write access to my twitter account and is not blocked. This problem appeared suddenly after a period of successful working for about a month, when tweets were posted every hour or so.

What is the problem here?

UPDATE It seems, that other guys also face this problem: https://dev.twitter.com/discussions/305

UPDATE 2 Finally, I have found out what caused the problem to appear in my case. Web app on production server tried to update a status with 140 characters (measured by String.Length property). And the first character was unicode Character 'LEFT-TO-RIGHT MARK' (U+200E). So, this text was passed to TwitterStatus.Update(..) without changes. I debugged a bit Twitterizer sources and noticed that oauth_signature(=hash) was calculated incorrectly. oauth_signature was generated from another url that was actually requested. I haven't cleared the reason why and when this error occurs and maybe will write more information in next few days.

UPDATE 3 I tried to post the same message with new version of Twitterizer (2.3.3) and no error occured. Problem disappeared.

It's the code, that I'm using to post a tweet:

OAuthTokens tokens = new OAuthTokens();
tokens.AccessToken = ConfigurationManager.AppSettings["twitterAccessToken"];
tokens.AccessTokenSecret = ConfigurationManager.AppSettings["twitterAccessTokenSecret"];
tokens.ConsumerKey = ConfigurationManager.AppSettings["twitterAutoPosterConsumerKey"];
tokens.ConsumerSecret = ConfigurationManager.AppSettings["twitterAutoPosterConsumerSecret"];

string text = "Some text";

TwitterResponse<TwitterStatus> tweetResponse = TwitterStatus.Update(tokens, text);
if (tweetResponse.Result == RequestResult.Success)
{
    // Tweet posted successfully!
    _log.InfoFormat("Posted a tweet #{0}.", tweetResponse.ResponseObject.Id);
}
else
{
    _log.ErrorFormat("Error occured while posting a tweet. Result = {0}. ErrorMessage = {1}",
        tweetResponse.Result, tweetResponse.ErrorMessage);
}
  • I'd like to talk to you after class, please. – Ricky Smith Aug 31 '11 at 17:04
  • I've written a letter to your email address at twitterizer.net – Mikhail Fiadosenka Sep 13 '11 at 17:59
  • @RickySmith I have the same issue right now - what can I do in order to solve it? Thanks, – JohnJohnGa Sep 20 '11 at 14:37
  • I tested new version of Twitterizer (2.3.3) with problematic message, and everything worked just fine. So, try to update your Twitterizer library. – Mikhail Fiadosenka Nov 5 '11 at 17:10
1

Please check in the message, if message have apostrophes (') , please replace it with &amp;#39;

Note that &amp;#39; will count as 5characters.

I think that apostrophes will effect the request package that send to twitter, that make twitter cannot get Token Correctly, so we will got error "Could not authenticate with OAuth".

0

I had the same trouble. PHP 5.3.1 ran on my local server, while PHP 4.3.2 ran on my production server. I use OAuth library of Google Code obtained from the below,

http://code.google.com/p/oauth/source/browse/#svn%2Fcode%2Fjavascript.

I explored the OAuth header which PHP proxy program received from javascript code on a browser. On my local server, it was

OAuth realm="",oauth_consumer_key="XXX",oauth_token="XXX",oauth_version="1.0",oauth_timestamp="1314956434",oauth_nonce="mF7Tof",oauth_signature_method="HMAC-SHA1",oauth_signature="DbuaiDeMhMYNZ5BaQmOoFr%2FRsEQ%3D"

while on my production server, all the double quotations above were escaped, namely, '\"'. So I replaced the escaped double quotation to the unescaped one using str_replace function. Then it got work well just the same on my production server. The cause is the difference of the way how double quotation is treated between PHP 5.3.1 and PHP 4.3.2. Escaped double quotation caused an error "Could not authenticate with OAuth."

  • My site is running on ASP.NET MVC 2, so I didn't face this problem. Anyway, your experience can be helpful for other people. – Mikhail Fiadosenka Sep 10 '11 at 12:24

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.