[SOLVED, but I'm open to new suggestions ...]
I integrate Twitter into my Android app using twitter4j.
When I try to log in using Twitter, I call 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 missing :- it should be MY-CALLBACK:///...)
Please note that I use WebView for my calls
I could manipulate this line to make everything work, but there should be a better way ...
I pass the callback url
getOAuthRequestToken("MY-CALLBACK:///");
and already set an intent filter for my activity using
<data android:scheme="x-oauthflow-twitter" />
, android:launchMode="singleInstance"
?
[edit: ]
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);
} 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);
} else {
view.loadUrl(url);
}
return true;
}
});
mTwitterReqToken = mTwitter.getOAuthRequestToken(Constants.TWITTER_CALLBACK_URL);
twitterWebView.loadUrl(mTwitterReqToken.getAuthenticationURL());
, " -", URL- :
https://api.twitter.comMY-CALLBACK///?oauth_token=***&oauth_verifier=***
url MY-CALLBACK:///?oauth_token=***&oauth_verifier=***, Intent, ...
" " , .