Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8072591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:04:06+00:00 2026-06-05T14:04:06+00:00

[SOLVED, but I’m open to new suggestions…] I’m integrating Twitter into my Android app

  • 0

[SOLVED, but I’m open to new suggestions…]

I’m integrating Twitter into my Android app using twitter4j.

When I try to authorize with Twitter, I am calling the following endpoint with my oauth token:

https://api.twitter.com/oauth/authenticate?oauth_token=MY_VALID_TOKEN

which should redirect me to:

MY-CALLBACK:///?oauth_token=***&oauth_verifier=***

but instead, it redirects me to:

https://api.twitter.comMY-CALLBACK///?oauth_token=***&oauth_verifier=***

which is obviously not a valid url.
(Also, the : is missing – it should be MY-CALLBACK:///...)

Please note I’m using WebView for my calls

I could manipulate this string to make everything work, but there has to be a better way…

I am passing my callback URL to

getOAuthRequestToken("MY-CALLBACK:///");

and have already set the intent-filter for my activity with

<data android:scheme="x-oauthflow-twitter" />

Also, the activity has android:launchMode="singleInstance"

What am I doing wrong?

[edit:more details]

mTwitter = new TwitterFactory().getInstance();
mTwitter.setOAuthConsumer(Constants.TWITTER_CONSUMER_KEY, Constants.TWITTER_CONSUMER_SECRET);

twitterWebView = new WebView(ActivityTwitterAuthorize.this);

twitterWebView.setWebViewClient(new WebViewClient() {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.startsWith(Constants.TWITTER_CALLBACK_URL)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            startActivity(intent);

        // HACKY PART!
        // I added the following code to force it to work, but this is a dirty hack...
        // String TWITTER_CALLBACK_INVALID_PREFIX = "https://api.twitter.comx-oauthflow-twitter///";
        // TWITTER_CALLBACK_URL = "MY-CALLBACK:///";
        // BEGIN
        } else if (url.startsWith(TWITTER_CALLBACK_INVALID_PREFIX)) {
            url = url.substring(TWITTER_CALLBACK_INVALID_PREFIX.length());
            url = Constants.TWITTER_CALLBACK_URL + url;
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            startActivity(intent);
        // END

        } else {
            view.loadUrl(url);
        }
        return true;
    }

});

mTwitterReqToken = mTwitter.getOAuthRequestToken(Constants.TWITTER_CALLBACK_URL);

twitterWebView.loadUrl(mTwitterReqToken.getAuthenticationURL());

WITHOUT the hacky part, this code results in “Webpage not available” error, because the url is invalid:

https://api.twitter.comMY-CALLBACK///?oauth_token=***&oauth_verifier=***

If the url was MY-CALLBACK:///?oauth_token=***&oauth_verifier=*** then my activity would receive an Intent, and everything would be ok…

WITH the “hacky part”, my code works, but I would like to avoid that piece of code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:04:09+00:00Added an answer on June 5, 2026 at 2:04 pm

    I found I just could not get it to work this way after following the guides I’ve seen online.

    I ended up using my own custom WebViewClient with the code:

    if ( url.contains( "MY-CALLBACK:///" ) )
    {
        final int start = url.indexOf( '?' ) + 1;
        final String params = url.substring( start );
        final String verifierToken = "oauth_verifier=";
        if ( params.contains( verifierToken ) )
        {
            final int value = params.indexOf( verifierToken ) + verifierToken.length();
            final String token = params.substring( value );
            view.stopLoading();                  
            authoriseNewUser( token );
        }
        else if ( params.contains( "denied" ) )
        {
            view.stopLoading();
            finish();
        }
    }
    else
    {
        view.loadUrl( url );
    }
    return true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: I have solved the majority of this problem but have run into a
This is something that I solved using reflection, but would like to see how
I've run into an easily solved but a design problem I've not encountered in
The problem written below the line is solved but i m facing a new
Update II Problem Solved but Why? This has been the biggest headache ever. My
I'd like to say that I solved the problem but I wanted post this
Edit 4/4/12 I STILL HAVE ONE QUESTION: I solved my issue but it adds
(Nearly solved, but not quite) (My temporary solution is to use a void method
I already have this issue but I cannot remember how to solved it. (I
This is solved, but I can't mark it as such for 2 days. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.