Search code examples
javaandroidtwitter-digits

Re-Authentication in Twitter Digits


I recently just started using Twitter Digits.

I'm having problems, the fact is that when I first logged in (sms came in with the code, went through the Authentication, and received a message in Toast "Authentication successful for").

But when the second time I try to open the page to fill the number, I press the button and I get again a message about successful authentication.

Code in onCreate method:

DigitsAuthButton digitsButton = (DigitsAuthButton) findViewById(R.id.auth_button);
        digitsButton.setCallback(new AuthCallback() {
            @Override
            public void success(DigitsSession session, String phoneNumber) {
                // TODO: associate the session userID with your user model
                Toast.makeText(getApplicationContext(), "Authentication successful for "
                        + phoneNumber, Toast.LENGTH_LONG).show();
            }

            @Override
            public void failure(DigitsException exception) {
                Log.d("Digits", "Sign in with Digits failure", exception);
            }
        });

Question: How do I clear a session or re-authorize?


Solution

  • You should call Digits.logout()

    /**
     * Log user out of this device - this clears the active Digits session, if one exists
     * Note: You will no longer get updates to the user's profile information
     * (email, phone number, etc) without an active Digits session.
     */
    public static void logout(){
        getInstance().sessionManager.clearActiveSession();
    }
    

    before calling

    Digits.authenticate();