Sometimes while implementing a Twitter to Android integration using an OAuth authentication with Signpost and Twitter4j we get unexpected results. Avoiding to use stronger words, for now, we’ll just say that that situation is bad.
Hard to debug, trace and resolve.
Few days ago we came to a pretty illogical situation. While we’re using a test application on Twitter for our purpose, we created a release Twitter app so that we put our latest projects on Google Store. We did everything as we did previously, noticing that the UI for the Twitter application creation has changed. You cannot choose whether the app is Client or Browser type and we were supposed to set permissions of the App (Read, Read/Write and Read, Write and Access direct messages). Other things changed too.
So we created our app and the very first try to share something over it on Twitter, we received the, for many infamous exception with the following message:
“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.”
While there were many suggestions on the web like, set the correct date/time or use the correct CONSUMER key, we didn’t manage to fix the issues for some time. Then, one of the last things we wanted to try was filling in the Callback URL field in our Twitter app settings. At first, we thought that it might have nothing to do with our application and that the field is only related to browser-type apps. But we were wrong. we put http://www.someurl.comas value of this field and tried to authorize again. It was success.
Not sure how the API wrapper or API interface itself is/are implemented. Android is using Intent filter for this purpose (as callback scheme) so this should be an issue. But it affected the normal functioning of our Twitter integration majorly. So now our Twitter sharing functionalities work just fine. We don’t say this is the only solution or solution at all, we just want to share something we went through ourselves. And it might help. Just give it a try!