Android fabric twitter authorize callback is not called

android
fabric
oauth
login

#1

I want to achieve Login with twitter inside fragment using TwitterAuthClient() how to solve

TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new Twitter(authConfig));

Code inside MyApplication .java

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);
     }
});

code inside onCreateView()

@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);
    }

These All the process working in activity but not in fragment so how to overcome these???


#2

You need to pass the result from your activity to the fragment. Something like this should work.

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

  // Pass the activity result to the fragment, which will then pass the result to the TwitterAuthClient.
  Fragment fragment = getFragmentManager().findFragmentById(R.id.your_fragment_id);
  if (fragment != null) {
      fragment.onActivityResult(requestCode, resultCode, data);
  }
}

This happen because internally we call activity.startActivityForResult().

See: https://docs.fabric.io/android/twitter/authentication.html#pass-the-activity-s-result-back-to-the-button


#3

@EricFrohnhoefer here which id pass as fragment id ?


#4