Android: E/Twitter﹕ Authorization completed with an error


#1

Hey all,

I’m having some troubles with the login in android.
Using the android button I’m getting an error after authorising the the app in twitter. A toast with “It is not possible to complete the action” and in the console:

 E/Twitter﹕ Authorization completed with an error
    com.twitter.sdk.android.core.TwitterAuthException: Authorize failed.
            at com.twitter.sdk.android.core.identity.AuthHandler.handleOnActivityResult(AuthHandler.java:80)
            at com.twitter.sdk.android.core.identity.TwitterAuthClient.onActivityResult(TwitterAuthClient.java:144)

I have an activity with a fragment. The fragment declares the callback before returning the view on onCreateView, and in onActivityREsult call to on activity result of the twitter button.
Also the main activity calls the fragment onActivityResult method.

My build.ggradle is like this:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'android-apt'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.+'
    compile('com.twitter.sdk.android:twitter:1.3.0@aar') {
        transitive = true;
    }
    compile('com.crashlytics.sdk.android:crashlytics:2.2.1@aar') {
        transitive = true;
    }
}

Any clue about it? it’s driving me crazy!

Thanks in advance!


#2

Hi there,

Is this failing when going through the single sign on flow (Twitter for Android app installed on your device)? If so, can you provide:

  1. Twitter for Android app version
  2. device information (manufacturer, OS version, etc)
  3. reproducibility rate (on same device, on different device like emulator)

Lien


#3

Hi Lien, thanks for your answer!

Yes it fails in that flow. I click on the twitter login button, the authorise app and a few seconds latter it returns to the app with the error I sent you.

Actually I only tested in a nexus 5 with android 5.0. I also have the twitter app installed. The twitter app version is 5.42.1

I also tried it with the following code and return the same error:

TwitterAuthClient client = new TwitterAuthClient();

client.authorize(this.getActivity(),new Callback<TwitterSession>() {
    @Override
    public void success(Result<TwitterSession> twitterSessionResult) {
        Log.d(TAG, "Logged with twitter");
        TwitterSession session = twitterSessionResult.data;
    }

    @Override
    public void failure(com.twitter.sdk.android.core.TwitterException e) {
        Log.e(TAG, "Failed login with twitter");
        e.printStackTrace();
    }
} );

Thanks!


#4

Hello Lien,

I’m still sucked with this error. Is some log or anything that I can send you to detect this error?

I really appreciate your help!

Thanks


#5

Hey Juan,

Any luck with this issue? I am facing the same trouble and it’s very inconsistent.
On 2 of my other android phones, the code is working like and charm but on my HTC 526 its failing again and again.

Lien,
I am using the latest Twitter app (v5.60.0)
Device info: HTC, Android 4.4
Was working a day before and suddenly got stuck

Any help is more than appreciated here.


#6

I’m affraid but I didin’t find a solution to this…

I used the web login instead the app login. It’s not the best solution because if you have twitter instaled and logged, you still have to write your pass and user.

To use the web login I used the socialauth library that make login and share easy but not as much configurable as I would like.

Best,


#7

I am facing a similar issue.
I am sharing my logcat part and the code.

Implementation:

  ...
  mTwitterAuthClient = new TwitterAuthClient();

  mTwitterAuthClient.authorize(MyActivity.this, new Callback<TwitterSession>() {
    @Override
    public void success(Result<TwitterSession> session) {
      TwitterAuthToken authToken = session.data.getAuthToken();
      String token = authToken.token;
      String secret = authToken.secret;
      LOGD(TAG, "token: " + token + " secret: " + secret);
      LOGD(TAG, "username: " + session.data.getUserName());
      Twitter.logOut();
    }
  
    @Override
    public void failure(TwitterException e) {
      LOGD("Twitter Login Failure", e.getMessage());
    }
  });
  ...
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    LOGD(TAG, "onActivityResult requestCode:" + requestCode + " resultCode:" + resultCode);
    mTwitterAuthClient.onActivityResult(requestCode, resultCode, data);
    super.onActivityResult(requestCode, resultCode, data);
  }

Logcat

06-11 11:25:02.571    5250-5250/my.app.package D/app_tag﹕ onActivityResult requestCode:140 resultCode:0
06-11 11:25:02.588    5250-5250/my.app.package E/Twitter﹕ Authorization completed with an error
    com.twitter.sdk.android.core.TwitterAuthException: Authorize failed.

Any ideas?


#8

Any luck with this? This just started happening to me today. I have no idea what I did but now I can’t authenticate at all. I use Fabric and use the single sign on flow. Help please?!


#9

Hi Lien,

I am facing the same issue and the interesting thing is that the login works smoothly on my phone(Android OS: lollipop). When i run the same application on my iball Slide Tab(Andropid OS: ICS) then this error shows up. Cant figure out what to do.

Thanks, any help would be appreciated


#10

Hey @all_about_bass,

This thread has morphed through a couple of different issues. Can you share the exact message you’re hitting - there should be some additional information now if you’re on the latest version of Digits.


#11

Please! After a year this still occurs.

Android SDK 25.0.0
Twitter SDK 2.2.0
Twitter APP 6.26.0
Nexus 5 Android 6.0.1

 E/Twitter: Authorization completed with an error
       com.twitter.sdk.android.core.TwitterAuthException: Authorize failed.

#12

Hey @dsdebastiani,

As mentioned previously, this thread has morphed in many different directions. Can you please share additional steps to reproduce this?


#13

Hi @bonnell,

I’m using Fabric and Twitter kit in my project to enable sign with Twitter account.

build.gradle:

buildscript {
    dependencies {
        classpath 'io.fabric.tools:gradle:1.22.0'
    }
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url "http://dl.bintray.com/pixplicity/maven" }
}
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.APP_ID"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 6
        versionName "0.6.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    aaptOptions {
        additionalParameters "--no-version-vectors"
    }
    buildTypes {
        debug {
            minifyEnabled true
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
            ext.enableCrashlytics = false
        }
        release {
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
            // Distribute
            ext.betaDistributionReleaseNotesFilePath = "app/release_notes.txt"
            ext.betaDistributionGroupAliasesFilePath = "app/group_aliases.txt"
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:support-v4:25.1.0"
    compile "com.android.support:appcompat-v7:25.1.0"
    compile "com.android.support:recyclerview-v7:25.1.0"
    compile "com.android.support:cardview-v7:25.1.0"
    compile "com.android.support:design:25.1.0"
    compile "com.android.support:support-annotations:25.1.0"
    compile "com.jakewharton:butterknife:8.4.0"
    annotationProcessor "com.jakewharton:butterknife-8.4.0"

    compile("com.crashlytics.sdk.android:crashlytics:2.6.5@aar") {
        transitive = true;
    }
    compile("com.twitter.sdk.android:twitter:2.2.0@aar") {
         transitive = true;
    } 
}

MainApplication.java

public class MainApplication extends Application {      
    private static final String TWITTER_KEY = "KEY";
    private static final String TWITTER_SECRET = "SECRET";
    @Override
    public void onCreate() {
        super.onCreate();
        Crashlytics crashlyticsKit = new Crashlytics.Builder()
            .core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
            .build();

        TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
        TwitterCore twitterCore = new TwitterCore(authConfig);

        Fabric.with(this, crashlyticsKit, twitterCore, new Twitter(authConfig));
    }
}

SiginActivity.java

public class SignActivity extends BaseActivity {
    private TwitterAuthClient mTwitterAuthClient;

    @BindView(R.id.btn_twitter)
    Button vBtnTwitter;
  
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign);
        ButterKnife.bind(this);
        mTwitterAuthClient = new TwitterAuthClient();
    }

    @OnClick(R.id.btn_twitter)
    public void onClick(View view) {
        mTwitterAuthClient.authorize(this, new Callback<TwitterSession>() {
                    @Override
                    public void success(Result<TwitterSession> result) {
                        TwitterSession session = result.data;
                        Log.d(TAG, session.getUserName() + " : " + session.getUserId());
                    }

                    @Override
                    public void failure(TwitterException exception) {
                        Toast.makeText(SignActivity.this, "Login with Twitter failed.", Toast.LENGTH_SHORT).show();
                    }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int responseCode, Intent data) {
        super.onActivityResult(requestCode, responseCode, data);
        mTwitterAuthClient.onActivityResult(requestCode,requestCode, data);
    }
}

The method mTwitterAuthClient.authorize() always failure with exception:

 E/Twitter: Authorization completed with an error
       com.twitter.sdk.android.core.TwitterAuthException: Authorize failed.
           at com.twitter.sdk.android.core.identity.AuthHandler.handleOnActivityResult(AuthHandler.java:98)
           at com.twitter.sdk.android.core.identity.TwitterAuthClient.onActivityResult(TwitterAuthClient.java:161)
           at com.APP_ID.ui.activities.SignActivity.onActivityResult(SignActivity.java:300)
           at android.app.Activity.dispatchActivityResult(Activity.java:6218)
           at android.app.ActivityThread.deliverResults(ActivityThread.java:3655)
           at android.app.ActivityThread.handleSendResult(ActivityThread.java:3702)
           at android.app.ActivityThread.access$1300(ActivityThread.java:155)
           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1366)
           at android.os.Handler.dispatchMessage(Handler.java:102)
           at android.os.Looper.loop(Looper.java:135)
           at android.app.ActivityThread.main(ActivityThread.java:5343)
           at java.lang.reflect.Method.invoke(Native Method)
           at java.lang.reflect.Method.invoke(Method.java:372)
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

#15

Closed as a duplicate of Getting authorization error when cancelling from twitter authorization using Fabric SDK


#16