HTTP request failed, Status: 401

android
authorization
twitterkit

#1

Hi, I’m using TwitterKit in my app for aut and Twitter requests. But I have one issue there.
When i try to add tweet to my favorites or make a retweet i always have error (calls like statuses/home_timeline works good)

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

Maybe I made a mistake in authorization part?
This is my code for authorization.:

 TwitterAuthClient mTwitterClient = new TwitterAuthClient();

    mTwitterClient.authorize(AccountsActivity.this, new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            Log.d("twirrer", "login_succes");
            TwitterSession session = Twitter.getSessionManager().getActiveSession();
            Twitter.getSessionManager().setActiveSession(session);
            TwitterAuthToken authToken = session.getAuthToken();
            final String token = authToken.token;
            getUserProfile(token);


        }

        @Override
        public void failure(TwitterException exception) {
            Log.d("twirrer", "login_err " + exception.getMessage());
        }
    });


 private void getUserProfile(final String userToken) {
    Call<User> user = Twitter.getApiClient().getAccountService().verifyCredentials(true, true);
    user.enqueue(new Callback<User>() {
        @Override
        public void success(Result<User> result) {
           
            Log.d("twirrer", "tw_profile_success");
        }

        @Override
        public void failure(TwitterException exception) {
            Log.d("twirrer", "tw_profile_err");
            exception.printStackTrace();
        }
    });
}

#2

A 401 generally indicates that the user isn’t authorized to Favorite or Retweet on behalf of the user that’s logged in. Are you seeing a login success before trying to do the post?

Getting a profile wouldn’t require the same explicit user authentication.

-Mike


#3

At first i call authorize() function of TwitterAuthClient. I receive “onSuccess” result, with auth token like this: 741593337912786944-kdhMjOAR0gbgIEZgtjyvRsM4trZd7ZY.

Then I call verify_credentials Api and there I have onSuccess too.

If i’m not authorized I had to get an error 401 when I call verify_credentials?


#4

Sorry for worry, im resolved my problem now. It is similar to my dev acc was wrong configured. Thank you for your help and answers so much.


#5

Glad to hear you’re all set and happy coding.


#6