Twitter: Failed to get app auth token / com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 403

android
fabric
digits

#1

I am following this Tutorial for Digits integration in my Android App . I am using Fabric plugin in Android Studio.

It is working fine in Samsung and Nexus 5 devices. But in Nexus 6 (Android 7.0) it is crashing after entering the phone number and click on Button (Send confirmation code). Below is the complete stack trace. Any help is appreciated.

E/Twitter: Failed to get app auth token
         com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 403
             at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
             at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
             at android.os.Handler.handleCallback(Handler.java:751)
             at android.os.Handler.dispatchMessage(Handler.java:95)
             at android.os.Looper.loop(Looper.java:154)
             at android.app.ActivityThread.main(ActivityThread.java:6077)
             at java.lang.reflect.Method.invoke(Native Method)
             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
        Process: com.xxx.xxx, PID: 18210
        java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.replace(java.lang.CharSequence, java.lang.CharSequence)' on a null object reference
            at com.twitter.sdk.android.core.internal.network.GuestAuthenticator.getExpiredToken(GuestAuthenticator.java:65)
            at com.twitter.sdk.android.core.internal.network.GuestAuthenticator.reauth(GuestAuthenticator.java:50)
            at com.twitter.sdk.android.core.internal.network.GuestAuthenticator.authenticate(GuestAuthenticator.java:45)
            at okhttp3.internal.http.HttpEngine.followUpRequest(HttpEngine.java:893)
            at okhttp3.RealCall.getResponse(RealCall.java:276)
            at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
            at com.digits.sdk.android.DigitsUserAgentInterceptor.intercept(DigitsUserAgentInterceptor.java:41)
            at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
            at com.twitter.sdk.android.core.internal.network.GuestAuthInterceptor.intercept(GuestAuthInterceptor.java:53)
            at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
            at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
            at okhttp3.RealCall.access$100(RealCall.java:30)
            at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
            at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
            at java.lang.Thread.run(Thread.java:761)

#2

Thanks for reaching out on this - it’s interesting that it only happens on a Nexus 6 and Android 7, but also that you’re getting an http auth error. Do you have any code differences when running on 7?


#3

I have a similar issue when try to execute request getFavoriteService().create(long id, boolean include_entities)

is there any way to solve it?

E/Twitter: Unexpected response
                                                                 java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.isEmpty()' on a null object reference
                                                                     at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
                                                                     at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
                                                                     at android.os.Handler.handleCallback(Handler.java:739)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                     at android.os.Looper.loop(Looper.java:158)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:7229)
                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

09-08 12:37:13.602 29348-29348/com.afdev.socialnewsviewer W/System.err: com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 401
09-08 12:37:13.602 29348-29348/com.afdev.socialnewsviewer W/System.err: at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
09-08 12:37:13.602 29348-29348/com.afdev.socialnewsviewer W/System.err: at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
09-08 12:37:13.602 29348-29348/com.afdev.socialnewsviewer W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
09-08 12:37:13.602 29348-29348/com.afdev.socialnewsviewer W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
09-08 12:37:13.602 29348-29348/com.afdev.socialnewsviewer W/System.err: at android.os.Looper.loop(Looper.java:158)
09-08 12:37:13.602 29348-29348/com.afdev.socialnewsviewer W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7229)
09-08 12:37:13.602 29348-29348/com.afdev.socialnewsviewer W/System.err: at java.lang.reflect.Method.invoke(Native Method)
09-08 12:37:13.602 29348-29348/com.afdev.socialnewsviewer W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
09-08 12:37:13.602 29348-29348/com.afdev.socialnewsviewer W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)


#4

Hmm, @fedorenkoalex92, that looks like to me like a different issue. Can you share more of your code? It looks like there is an issue with where the request is being called from.

-Mike


#5

I have this issue when i try to add tweet to favorites. Other calls works Ok. My device Samsung s7 on Android 6. This is my code

Call request = Twitter.getApiClient().getFavoriteService().create(item.getPostId(), false);

    request.enqueue(new Callback<Tweet>() {
        @Override
        public void success(Result<Tweet> result) {
            Log.d("twitter_like", "ok");
           
        }

        @Override
        public void failure(TwitterException exception) {
            exception.printStackTrace();


        }
    });

#6

Can you share the logcat output from when this is failing?


#7

When I call Twitter.getApiClient().getFavoriteService().create(postId, false) I see in log

09-09 09:45:32.604 26782-26782/com.afdev.socialnewsviewer E/Twitter: Unexpected response
java.lang.NullPointerException: Attempt to invoke interface method ‘boolean java.util.List.isEmpty()’ on a null object reference
at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
09-09 09:45:32.604 26782-26782/com.afdev.socialnewsviewer W/System.err: com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 401
09-09 09:45:32.604 26782-26782/com.afdev.socialnewsviewer W/System.err: at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
09-09 09:45:32.604 26782-26782/com.afdev.socialnewsviewer W/System.err: at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
09-09 09:45:32.604 26782-26782/com.afdev.socialnewsviewer W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
09-09 09:45:32.604 26782-26782/com.afdev.socialnewsviewer W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
09-09 09:45:32.604 26782-26782/com.afdev.socialnewsviewer W/System.err: at android.os.Looper.loop(Looper.java:158)
09-09 09:45:32.604 26782-26782/com.afdev.socialnewsviewer W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7229)
09-09 09:45:32.604 26782-26782/com.afdev.socialnewsviewer W/System.err: at java.lang.reflect.Method.invoke(Native Method)
09-09 09:45:32.604 26782-26782/com.afdev.socialnewsviewer W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
09-09 09:45:32.604 26782-26782/com.afdev.socialnewsviewer W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)


#8

@fedorenkoalex92 The error indicates you are not logged-in. One can only favorite a Tweet using user auth. Also seems like an API error object wasn’t returned, which seems odd. Response should also include error message like:

{"errors":[{"code":220,"message":"Your credentials do not allow access to this resource."}]}

I will make sure we add a null check there.

@DalilyCallerID Looks like guest auth failed for the original request. When we retry the request we look for the original token. Since the token wasn’t included in the original request we receive a NullPointerException. I will make sure we add a null check there.


#9

We also are having the issue, in fact this is the #2 reason of crash in our app, so you have an ETA for the fix?
on our side it’s happening on a wide variety of device and OS and only since the last upgrade to twitter 2.0.0 along with its dependencies.:
Please advise, thanks

Fatal Exception: java.lang.NullPointerException

Attempt to invoke virtual method ‘java.lang.String java.lang.String.replace(java.lang.CharSequence, java.lang.CharSequence)’ on a null object reference
com.twitter.sdk.android.core.internal.network.GuestAuthenticator.getExpiredToken (GuestAuthenticator.java:65)
com.twitter.sdk.android.core.internal.network.GuestAuthenticator.reauth (GuestAuthenticator.java:50)
com.twitter.sdk.android.core.internal.network.GuestAuthenticator.authenticate (GuestAuthenticator.java:45)


#10

Hey @olivier_calea,

Thanks for reaching out on this and sorry that you’re hitting this issue. That stack trace looks a little different then the one above - can you share a link to this issue on your Crashlytics dashboard or a full crash log? Would love to dig into it!

-Mike


#11

can you access this? :
https://www.fabric.io/calea/android/apps/com.calea.echo/issues/57db7f4a0aeb16625b5015f1
thanks!


#12

Thanks for the link, will review with the team.


#13

@olivier_calea The fix for that is also planned for the next release. I don’t have a date yet, but we’re working on it.


#14

@DalilyCallerID @olivier_calea We are in the process of releasing Twitter/Digits 2.0.1 now. This change should be publicly available soon.


#15