views:

6464

answers:

5

I'm trying to use Twitter's API and OAuth to send status updates (new Tweets). I am using Shannon Whitley .NET code example http://www.voiceoftech.com/swhitley/?p=681 (as recommended on the Twitter API docs). I can read (GET) using OAuth just fine, however when I try to send a status update via http ://twitter.com/statuses/update.xml (using a POST), it returns a 401 with the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <request>/statuses/update.xml</request>
  <error>Read-only application cannot POST</error>
</hash>

I swear I have set up my application to use read and write, the authorise page at Twitter (http ://twitter.com/oauth/authorize) even says "The application TweeVerbs.com (Development) by would like the ability to access and update your data on Twitter."

Yet it's still saying "Read-only application cannot POST". WTF!?

I have googled this error message until I was blue in the face. I found somewhere that said to add the querystring paremeter *oauth_access_type=write* to the redirect URL which goes to the Twitter authorise page which I have done, but it still gives me a 401.


If it helps, here is the data that is getting sent back and firth as per the OAuth workflow:

Request Authorise Token:

http ://twitter.com/oauth/request_token?oauth_consumer_key=tViV8vAt4cqSKbGdPGWT7Q&oauth_nonce=2790042&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1244567068&oauth_version=1.0&oauth_signature=KzxcXN%2bQ0AJoAJ%2flQfzs8SLjC%2fQ%3d

Generated Authorize Redirect URL:

http ://twitter.com/oauth/authorize?oauth_token=EpyBg3nJGOmtmBjRUAsqqaGHARb2F2F2VcccqHkwio&oauth_access_type=write

Authorise Screen Message: "The application TweeVerbs.com (Development) by would like the ability to access and update your data on Twitter. This application plans to use Twitter for logging you in in the future. Sign out if you want to connect to an account other than Sironfoot."

Get Access Token:

http ://twitter.com/oauth/access_token?oauth_consumer_key=tViV8vAt4cqSKbGdPGWT7Q&oauth_nonce=2016804&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1244567166&oauth_token=EpyBg3nJGOmtmBjRUAsqqaGHARb2F2F2VcccqHkwio&oauth_version=1.0&oauth_signature=%2bEVQUxUPLT%2b%2bkfaG0Vq1YJZXcAw%3d

Status Update API call: URL - http ://twitter.com/statuses/update.xml POST data - oauth_consumer_key=tViV8vAt4cqSKbGdPGWT7Q&oauth_nonce=5707692&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1244567268&oauth_token=19130957-nb89DjZhjCAzcbHUa96yRWHqlQFQIJ0AKyXpqnHt1&oauth_version=1.0&status=HelloWorld&oauth_signature=WqA%2bWY0IxveeSJ7G3Ewy3whh1sE%3d

+6  A: 

Dunno what the problem was, but I deleted my Application registration on Twitter (You have to register apps in Twitter to get OAuth keys etc.), and then recreated it. Now it works fine. Weird, probably a problem with Twitter screwing up.

I'm also using Tweetsharp (http://tweetsharp.com/), highly recommend it, it's got a nice fluent API. Note: switching over to Tweetsharp wasn't the fix, I had already switched over and had the same problem until I delete and recreated app registration on Twitter.

Sunday Ironfoot
that solved my problem too ... it seems twitter has problem changing a read-only app to read-write.
seanlinmt
A: 

I've dont that several times now, without succes, I'm getting a 401 exception while requesting an acces token from twitter.

I'm using Tweetsharp as well as you.

Proxdeveloper
A: 

If you authorized your application to access your Twitter account when the application was set in "read only access" mode and you get the "Read-only application cannot POST" error after changing the application settings to be "read and write access" then you have to revoke access to the application on https://twitter.com/settings/connections and then reauthorize it. The "read only" access_token tends to be sticky until you revoke it.

abraham
A: 

plus also see if your system's CLOCK is synched with internet; on windows you can do it by adjusting date time settings

because if you CLOCK is not synched you will get 401 unauthorized exception; best of luck cheers

hira
A: 

Hope this helps.

Waqas