Someone might be looking for integrating twitter to their android application. I found few alternatives(more than enough) on the web. I’l be talking about few of them on my upcoming posts. All this libraries are unofficial, not provided by twitter itself as there isn’t any official twitter sdk available for android. In this post i’l be talking about one library that i recently used, its Twitter4J. I am again not writing any tutorial for using it. I am here to share some pitfall i fell into, which many people can face for first time. But don’t worry, there is THIS BLOG which has full detail on setting up Twitter4J with your project and get you started tweeting in no time(techically 30 minutes :P).

So i suppose now you have setup the project as detailed in that blog. Now if everything is working than Good Job, if its not working for you yet then go through the steps again and see if you are not missing something. But if you are having problem that i faced and which i will be talking about it here then “GOOD JOB” too 😛

I faced two problems which are very basic but critical.

“oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match.”

This error gave me lotsa pain since it was very difficult to find the reason. I spent many hours figuring out what was happening. Error is very specific which states that consumer key might not be matching. But i cross checked keys and everything, everything was in place, so what could be the possible reason ? Then all of a sudden, somehow i just fixed the issue like hitting my hand everywhere or shooting the arrow in dark. I was so desperate. So thing that was causing this issue was, during resgistration of app on, Callback URL value wasn’t provided. Yeah i didn’t provide any callback url because it was optional, so i skipped it. So i provided a callback url, you can provide anything there. Now you’l find that above error doesn’t happens anymore and you can start tweeting from your app.

“error – Read-only application cannot POST”

Second issue i faced was this, and this one is very easy to figure out and fix it. It means that your registered twitter app is read only. So go to settings page of your application and make it “read and write”. Thats it.

I am showing you the screenshot of how settings will look like.