Android TwitterLoginButton Callbacks : Neither success nor failure


#1

Hi,

I’m trying to implement a TwitterLoginButton in a Login activity, I followed every step and looked for a solution everywhere but I still can’t manage to get a proper Twitter session in my app.

When I click on the button, I’m redirected to the Twitter app for authorization, but nothing happens when I click “authorize”, neither success nor failure callback is called.

Here’s my code :

public class Login extends ActionBarActivity {

private static final String TWITTER_KEY = "(CONSUMERKEY)";
private static final String TWITTER_SECRET = "(SECRETKEY";

private TwitterLoginButton loginButton;

private void setUpTwitterButton() {
    loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
    loginButton.setCallback(new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            
            Log.i("success?", "success");
            // Do something with result, which provides a
            // TwitterSession for making API calls

        }

        @Override
        public void failure(TwitterException exception) {
            Toast.makeText(getApplicationContext(),
                    "Signin fail",
                    Toast.LENGTH_SHORT).show();
            Crashlytics.logException(exception);
        }


    });

}

public void onCreate(Bundle savedInstanceState)
{

	super.onCreate(savedInstanceState);

    this.overridePendingTransition(R.anim.right_to_left_enter,
            R.anim.right_to_left_leave);

    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig), new Crashlytics());
    setContentView(R.layout.login);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
    }

    toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
    toolbar.setLogo(R.drawable.actionlogo);
    setUpTwitterButton();

} 

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

    // Pass the activity result to the login button.
    loginButton.onActivityResult(requestCode, resultCode,
            data);
}

Thank you very much for your help!


#2

Nevermind… I don’t know why, I didn’t change anything but now it works, I don’t understand but that’s great!


#3

Hi LunyCalvin,

Glad to hear that things are working for you! If you ever encounter an issue like this where you don’t know what’s going on, you can enable debug logging to get more information. To do this, update your Fabric.with call to something like:

        final Fabric fabric = new Fabric.Builder(this)
            .kits(new Twitter(authConfig))
            .debuggable(true) // <----- set to true to see more logs
            .build();
        Fabric.with(fabric);

Then you can include log snippets with your post to help folks debug the issue with you.

Lien


#4