ERROR: com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 401

android
fabric
authorization
error-codes
api

#1

I’m working on this app that is going fine on my cellphone, but is not on Android Studio’s Emulators.

After a while I start to receive this message from the API:

ERROR: com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 401

The app starts working ok, and after some calling messages to twitter API (5 more or less), error 401 starts showing.

I’m using Android Studio with FABRIC

Could it be a problem with session? Expired maybe? Aplication works for only a minute or 2.

I am monitoring limits, and i’m far from extrapolate it, in some tests i have the error 401 with 897 X-Rate-Limit-Remaining.

Library and Fabric is updated.

I manually set the date on emulator to not have any time problems (i saw something like this on forums).

This problem is putting me crazy. I’m working for 3 months already on this app, and 2 days ago the problem started.

Please, if someone knows all about it, every tip will be blessed.

Thank’s!


#2

Hey @CrazyMindsGames,

Can you share the full error from Logcat that you’re seeing?

-Mike


#3

This is the stack returned from callback of one of the APIs i am using now:

======================================================================
W/System.err: com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 401
W/System.err: at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
W/System.err: at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err: at android.os.Looper.loop(Looper.java:148)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

There is no other error but this.

Thank’s in advanced.


#4

In this use case i am trying to list status from other user.

Here is the code I made the call:

    StatusesService ss = Twitter.getApiClient(Twitter.getSessionManager().getActiveSession()).getStatusesService();
    Call<List<Tweet>> callFollow = ss.userTimeline(id, null, 20 ,null,null, true,true,false,false );
    callFollow.enqueue(new Callback<List<Tweet>>()
    {
        @Override
        public void success(final Result<List<Tweet>> twits)
        {
        .....
        }

        @Override
        public void failure(final TwitterException exception)
        {
                    Log.d("AutomaticTwitActivity", " - StealingTwitFromTarget - ERROR: " + exception.toString()
                            + " Cause:" + exception.getCause()
                            + " LocalMessage:" + exception.getLocalizedMessage()
                            + " Message:" + exception.getMessage()
                            + " Stack:" + exception.getStackTrace().toString()
                            + " Supressed:" + exception.getSuppressed().toString()
                            );

                    exception.printStackTrace();
       }

“ss.userTimeline()” comes from StatusesService interface, StatusesService.java(package com.twitter.sdk.android.core.services;).


#5

Thanks, I’ll try to reproduce this on Monday - much appreciated for the details!


#6

it’s important to rebember the follow:

  • problem only occurring now on emulator;
  • is working on device;
  • problem occurs after a while;
  • no error, just 401 returns from server.

Thank you!


#7

Hello Bonnell!

I spent the whole weekend without touching the project, i dont even ran it.
Unexpectedly it dawned on Monday working. What I mean is that my calls that were returning status 401 are no longer doing it.

Would my test account was on some kind of black list?


#8

Hey @CrazyMindsGames,

It’s possible that you hit a rate limit, but I’m glad to hear you’re all set. I haven’t been able to reproduce this myself yet.


#9

Hi Bonnell

I suspect too of the rate limit, but, the problem is, if it’s correct, it should give me another error. 429, right?

https://dev.twitter.com/overview/api/response-codes


#10

Yes, normally a rate limit would come through as a 429 and not a 401, so I’m a bit surprised by it.


#11

I let my app running all the day and started to give me 401 error. With no error code explaining what happens.
Almost sure is a daily rate limit occurring here. Sadly i’m not receiving a 429 status.
Would it be a bug at twitter side?

Thank’s!


#12

Hey @CrazyMindsGames,

This happened on the emulator again? Also, when you mention that it was running all day - it was active and in the foreground? A 401, I did more digging, is definitely an authorization and not a rate limit issue. Can you share any Logcat output from when this happened?


#13

Hi Bonnell,

Yesterday I had problem with the status 401 all day, on the device, the same on the emulator. With different twitter test accounts.

Today, i had no problem yet. With every account I used, and every platform(device/emulator).

it’s very wierd.


#14

Hey @CrazyMindsGames,

I haven’t been able to reproduce this locally still? Do you have any more details to help track this down based on anything other then day?


#15

Hi Bonnell,

This application automates small tasks. It does a kind of automatic things like pre-registered twit every 5 min (if they exist in the database), polls, likes in my updates, etc.
I suspect that at some point I set the wrong time for these small tasks, and the expected may have happened: Rate limits were crossed.

I did not find any kind of error in the logcat logs. And after a while the 401 status begins.


#16

Hmm, I can take a look at your Twitter Consumer key and check it’s status if you email it into support(at)fabric(dot)io and reference this thread.