Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android fabric twitter authorize callback is not called

I have started using Twitter Fabric for Android. Login with TwitterLoginButton is working fine, but in some cases I don't need to use TwitterLoginButton, I just need to get user token and secret. The code looks right, twitter login form is opened but callback is called at all.

TwitterAuthClient authClient = new TwitterAuthClient();
authClient.authorize(TwitterSettingsActivity.this, new Callback<TwitterSession>() {
     @Override
     public void success(Result<TwitterSession> twitterSessionResult) {
         Logger.e(TAG, "ok");
     }

     @Override
     public void failure(TwitterException e) {
         Logger.e(TAG, "failure error", e);
     }
});

I guess I need to add some handling in onActivityResult but there is no info about it in the doc https://dev.twitter.com/twitter-kit/android/request-email

like image 376
Vadims Savjolovs Avatar asked Dec 10 '14 15:12

Vadims Savjolovs


1 Answers

You're right that you need to add some handling in an onActivityResult to get the callback. To pass the Activity’s result back so that your callback receives it, you can do the following:

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

        // Pass the activity result to the auth client.
        authClient.onActivityResult(requestCode, resultCode, data);
    }

This is essentially what the TwitterLoginButton is doing in its TwitterLoginButton#onActivityResult method.

like image 183
Lien Avatar answered Oct 21 '22 23:10

Lien