Failed to connect to Twitter API using TwitterKit on Android


I’m using twitter-kit to make authentication with twitter. I choose to use TwitterAuthClient instead of TwitterLoginButton. Everything goes fine when I tested on emulator (genymotion), but when I tried with real device (Nexus 5, android 4.4), this error occurs Failed to get request token
        at retrofit.CallbackRunnable$
        at android.os.Handler.handleCallback(
        at android.os.Handler.dispatchMessage(
        at android.os.Looper.loop(
        at java.lang.reflect.Method.invoke(Native Method)
 Caused by: failed to connect to (port 443) after 15000ms: isConnected failed: EHOSTUNREACH (No route to host)
        at retrofit.RestAdapter$RestHandler.invokeRequest(
        at retrofit.RestAdapter$RestHandler.access$100(
        at retrofit.RestAdapter$RestHandler$2.obtainResponse(
        at java.util.concurrent.ThreadPoolExecutor.runWorker(
        at java.util.concurrent.ThreadPoolExecutor$
        at retrofit.Platform$Android$2$

It said fail to connect after 15000ms but I get that error right away when trying to go to authen flow.

Do anyone have a way to fix it ?


Hi there,

From the stack trace, it looks like a network connectivity issue,

Caused by: failed to connect to (port 443) after 15000ms: isConnected failed: EHOSTUNREACH (No route to host)

Are you able to access twitter from your device’s web browser?


If dont install Twitter client, error log.

E/Twitter (32531): 401 Authorization Required
E/Twitter (32531): 	at retrofit.RestAdapter$RestHandler.invokeRequest(
E/Twitter (32531): 	at retrofit.RestAdapter$RestHandler.access$100(
E/Twitter (32531): 	at retrofit.RestAdapter$RestHandler$2.obtainResponse(
E/Twitter (32531): 	at
E/Twitter (32531): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(
E/Twitter (32531): 	at java.util.concurrent.ThreadPoolExecutor$
E/Twitter (32531): 	at retrofit.Platform$Android$2$
E/Twitter (32531): 	at
E/Twitter (32531): Authorization completed with an error
E/Twitter (32531): Failed to get request token
E/Twitter (32531): 	at$1.failure(
E/Twitter (32531): 	at$1.failure(
E/Twitter (32531): 	at
E/Twitter (32531): 	at retrofit.CallbackRunnable$
E/Twitter (32531): 	at android.os.Handler.handleCallback(
E/Twitter (32531): 	at android.os.Handler.dispatchMessage(
E/Twitter (32531): 	at android.os.Looper.loop(
E/Twitter (32531): 	at
E/Twitter (32531): 	at java.lang.reflect.Method.invoke(Native Method)
E/Twitter (32531): 	at java.lang.reflect.Method.invoke(
E/Twitter (32531): 	at$
E/Twitter (32531): 	at
W/System.err(32531): Failed to get request token
W/System.err(32531): 	at$1.failure(
W/System.err(32531): 	at$1.failure(
W/System.err(32531): 	at
W/System.err(32531): 	at retrofit.CallbackRunnable$
W/System.err(32531): 	at android.os.Handler.handleCallback(
W/System.err(32531): 	at android.os.Handler.dispatchMessage(
W/System.err(32531): 	at android.os.Looper.loop(
W/System.err(32531): 	at
W/System.err(32531): 	at java.lang.reflect.Method.invoke(Native Method)
W/System.err(32531): 	at java.lang.reflect.Method.invoke(
W/System.err(32531): 	at$
W/System.err(32531): 	at
W/FlurryAgent(32531): Flurry session started for context:com.oxa7.shou.LandingActivity@9a83c34



If you don’t have the Twitter client installed, we fall back to webview to complete the authorization flow. Some things to check:

  1. Your device time is correct and up to date
  2. “Allow this application to be used to Sign in with Twitter” is set in your twitter app’s settings.
  3. You have a callback url configured for your twitter app.



Thank you, add callback url work well, please add top on website when developer create app.