Android frequently returns TwitterApiException loading tweets

android

#1

We have integrated the Twitter Fabric SDK into our Android app according to the instructions on the “Log in with Twitter” developer page; specifically, we’re using a TwitterLoginButton inside a Fragment. Sometimes the process works smoothly, and we get tweets from our requested timeline returned to our TweetViewAdapter.

Most of the time, however, we get various TwitterApiExceptions returned deep within the bowels of the SDK, specifically retrofit.RestAdapter$RestHandler.invokeRequest(), ranging from “Socket is closed”, “Handshake failed”, to “Shutdown”. Our fragment’s onActivityResult() is getting called in these cases as well, with the returned data dutifully passed on to the TwitterLoginButton. After that, we have fulfilled our contractual obligation to handle handshaking with the Twitter Fabric SDK and can only rely on it to process the contents of the Intent data.

If our application were not set up correctly we would never get a valid access token, but we’ve never failed to authorize, just download tweets. Our results are the same whether we login via a web browser or the native Twitter client. We’ve also used a range of Twitter Kit versions up through 1.6, all to no avail. The intermittent nature of the errors is troublesome. I have noticed a couple of related tickets posted on the forums, but neither of them have received a resolution.

Please let us know if there is anything not documented on the developer pages which would affect our implementation. Thanks for your time.


#2

Hi @robbandrewyoung,

Thank you for feedback. The errors you described are low level networking issues. These could be caused by poor network connections for example. Could you email support@fabric.io with more details? If you are using Crashlytics an link to the crash would be helpful. Otherwise, please send relevant details such as stack trace, device name, os version, openssl version, etc.


#3

Thanks Eric, I appreciate your taking the time to respond. I decided to try stripping my project down to a simple test case which would demonstrate the issue, but when I copy-and-paste the same code into a simple Activity with embedded Fragment, everything seems to work without a hitch.

We’ve seen this before with third-party SDKs, which work as advertised with simple layouts but run into problems when the interface becomes more involved. So I’ll have to keep adding some complexity to my lightweight sample app before I’ll be able to reproduce the issue. At least it verifies for me that my Twitter integration is properly coded, so now I’m intrigued to discern what else differs between my Twitter-enabled applications.

As soon as I have a test application that exhibits the reported problems I will forward it to you, along with the full spectrum of crashes that I have managed to log thus far.


#4

Eric,

I believe I’ve finally tracked down the offender. We have our own networking classes built atop HttpUrlConnection. To ease our eventual migration to OkHttp, we were compiling the okhttp-urlconnection module into our code. That module was causing the intermittent failures we’ve been seeing with Twitter. Once we removed this optional module from our code, the Twitter failures ceased.

If you are still interested in seeing the kinds of exceptions that were getting thrown, I have a record of the various stack traces we’ve seen over the past couple of months. I still can’t fathom why the Twitter SDK is experiencing these low-level failures as a result of the inclusion of this module, but it’s good to know for future reference that there currently exists an incompatibility.

Thank you for your help, it means a lot to get responses to our questions!


#5

Good to hear you are no longer experiencing any issues.


#6