I'm writing an application that includes a sign in with twitter button. The button is okay. It shows on the screen when I click I give auth but I cant save the token and secret to a string variable. I mean it is empty always. The code at the below has been created by fabric.io automatically and I have added some stuff in it but it is not working. There is no error it just doesn't change the variable token and secret. I have tried this by an TextView object that changes in the success case and it never changes. What should I do? I just want to save token and secret to get user's information another time.
loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
loginButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
System.out.println("Okay we are logged in now!");
TwitterSession session = Twitter.getSessionManager().getActiveSession();
TwitterAuthToken authToken = session.getAuthToken();
token = authToken.token;
secret = authToken.secret;
String answers = "";
User user = new User(userid,token,secret,answers);
registerUser(user);
twitterauth = true;
}
@Override
public void failure(TwitterException exception) {
// Do something on failure
}
});
EDİT: I'm taking an error like the following, if I click the sign in with Twitter button again:
2660-2660/com.website.nameofmyapp E/Twitter﹕ Authorization completed with an error
com.twitter.sdk.android.core.TwitterAuthException: Authorize failed.
at com.twitter.sdk.android.core.identity.TwitterAuthClient.handleAuthorize(TwitterAuthClient.java:110)
at com.twitter.sdk.android.core.identity.TwitterAuthClient.authorize(TwitterAuthClient.java:101)
at com.twitter.sdk.android.core.identity.TwitterLoginButton$LoginClickListener.onClick(TwitterLoginButton.java:161)
at android.view.View.performClick(View.java:5184)
at android.view.View$PerformClick.run(View.java:20910)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
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:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
All I want to do is simple to start a new activity when "success" happens automatically.
it looks like your code is good, the problem is not there. I write you example how i have done it.