title: Twitter API returns invalid callback - Cannot authorize
body: <p>[SOLVED, but I'm open to new suggestions...]  </p>
  
  <p>I'm integrating Twitter into my Android app using twitter4j.<br>
  <br></p>
  
  <p>When I try to authorize with Twitter, I am calling the following endpoint with my oauth token:</p>
  
  <p><code>https://api.twitter.com/oauth/authenticate?oauth_token=MY_VALID_TOKEN</code></p>
  
  <p>which <strong>should</strong> redirect me to:</p>
  
  <p><code>MY-CALLBACK:///?oauth_token=***&amp;oauth_verifier=***</code></p>
  
  <p>but instead, it redirects me to:</p>
  
  <p><code>https://api.twitter.comMY-CALLBACK///?oauth_token=***&amp;oauth_verifier=***</code></p>
  
  <p>which is obviously not a valid url.<br>
  (Also, the <code>:</code> is missing - it should be <code>MY-CALLBACK:///...</code>)<br>
  <br>
  Please note I'm using WebView for my calls<br>
  <br>
  <br>
  I could manipulate this string to make everything work, but there has to be a better way...<br>
  <br>
  <br>
  <br>
  I am passing my callback URL to  </p>
  
  <p><code>getOAuthRequestToken("MY-CALLBACK:///");</code></p>
  
  <p>and have already set the intent-filter for my activity with</p>
  
  <p><code>&lt;data android:scheme="x-oauthflow-twitter" /&gt;</code></p>
  
  <p>Also, the activity has <code>android:launchMode="singleInstance"</code><br>
  <br>
  <br>
  <br>
  What am I doing wrong?<br>
  <br>
  <br>
  [edit:more details]  </p>
  
  <pre><code>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());
  </code></pre>
  
  <p>WITHOUT the hacky part, this code results in "Webpage not available" error, because the url is invalid:</p>
  
  <p><code>https://api.twitter.comMY-CALLBACK///?oauth_token=***&amp;oauth_verifier=***</code></p>
  
  <p>If the url was <code>MY-CALLBACK:///?oauth_token=***&amp;oauth_verifier=***</code> then my activity would receive an Intent, and everything would be ok...</p>
  
  <p>WITH the "hacky part", my code works, but I would like to avoid that piece of code.</p>