Three days ago, I was contacted by a Tile Me! user telling me that the Twitter integration in the app did not work for him. I checked on my phone, everything was fine. I could also see other people were using it just fine too. So, I gave the default instructions of “Have you tried reinstalling the app?"’ which did not help 😦 .
Yesterday, I gave the user an account name and password that I control for app testing, just to see if the problem is with the app or the account he is trying to log in with. Lo and behold it works, while his accounts (yes he created several) don’t. That doesn’t make sense, does it?
After this, I decided to create a new Twitter account myself and test with that. Of course it does not work. I got in touch with Robert Shurbet and Sébastien Lachance who are both using TweetSharp in their apps. Robert said that he encountered this error before and he coded the authentication with a RestClient himself, while Sébastien was not aware of this issue which caused his app to crash altogether. The guy user that first reported this problem had created his Twitter account in February 2014. So, this problem might have been there for a while.
If you are using TweetSharp 2.3.0 (which is the stable version) or a modified 2.3.1, try creating a new Twitter account and see if you can log-in with it. If you can’t, read on.
I noticed that the problem was with the access tokens. For some reason, TweetSharp was returning a ‘null’ access token when I logged in with a newly created Twitter account. I examined the TwitterResponse object which at first glance seemed fine. The status said ‘OK’. But, clearly it was not OK. After digging some more, I found out that an inner exception had occurred during the processing of the access token and was logged in the TwitterResponse object.
The exception that was logged said something along the lines of “Value assigned is greater than Int32’. I thought that must be it. They probably changed the type of something from’ ‘int’ to ‘long’. To investigate further, I had to download the TweetSharp 2.3.0 source code.
Now that I could access the TweetSharp classes, I found out that the culprit was the ‘UserId’ in the OAuthAccessToken class.
The solution was quite simple. Change the ‘UserId’ type from ‘int’ to ‘long’ and find what else I broke by doing that. After building the project, I got a few errors at a few lines in the TwitterService.OAuth.cs class where the ‘UserId’ property was used.
In order to fix the errors all I had to do was replace all the occurrences of:
UserId = Convert.ToInt32(query["user_id"] ?? "0"),
UserId = Convert.ToInt64(query["user_id"] ?? "0"),
I built the project, replaced the .DLL that I was using from nuget with the newly compiled one, and voila everything was fixed. I also sent the .DLL to Sébastien which reported that the problem was fixed in his app as well.
If you want to edit the things yourself, download the source code and do the changes above. If you are lazy to do that, don’t worry, you can download the Windows Phone 8 .DLL I compiled from here. If you installed TweetSharp from nuget, just navigate to your project directory –> Packages –> TweetSharp.2.3.0 –> lib –> sl4-wp and replace TweetSharp.WindowsPhone.dll
If you are using TweetSharp for WP7 or another platform, you’ll have to do the changes yourself (it’s the same ones).
Note: The developer has stopped supporting TweetSharp, so if you are creating a new app, use another alternative instead. I cannot guarantee that TweetSharp won’t break again anytime soon. I heard Linq2Twitter is currently popular among developers.