0

I have integrated Twitter in android application using twitter4j library and it works fine with posting on Twitter.

I handle it well when user signs in and then flow comes back to application. I continue with status update in this case.

But the problem occurs when user clicks cancel button instead of sign in. How do I know that user clicked cancel button?

Geek
  • 8,280
  • 17
  • 73
  • 137
  • Dare to answer if you have any, instead of down voting. Also post the reason for your down vote. – Geek Jul 10 '13 at 16:30

1 Answers1

1

I solved this problem by peeking into Intent passed in call back.
When user signs in, Intent contains a parameter oauth_verifier, whereas when user denies to continue by clicking on cancel button, Intent contains a parameter denied.

// Handle Twitter call back
private void handleTwitterCallBack() {

    Uri uri = getIntent().getData();

    // If got redirected from Twitter page to application
    if (uri != null
            && uri.toString().startsWith(RS_Twitter.TWITTER_CALLBACK_URL)) {

        if (uri.getQueryParameter(RS_Twitter.TWITTER_USER_DENIED) != null) {

            // User denied to sign in

        } else if (uri
                .getQueryParameter(RS_Twitter.TWITTER_OAUTH_VERIFIER_URL) != null) {

            // Intent contains Twitter verifier. User authorized the application.
        }
    }
}
Geek
  • 8,280
  • 17
  • 73
  • 137