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!