I have code from a previous Android app which I successfully integrated with Twitter. I've copied this code over to a new app and changed the callback-url
, consumer-key
and consumer-secret
for my new app.
Using the twitter4j
library I'm able to get my RequestToken
and authentication url as follows:
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(myConsumerKey, myConsumerSecret);
RequestToken requestToken = twitter.getOAuthRequestToken(myCallbackUrl);
String authenticationUrl = requestToken.getAuthenticationURL()
The RequestToken
has a non-null token
value, a non-null tokenSecret
value, and a null secretKeySpec
value. The authentication url is of the following form:
http://api.twitter.com/oauth/authenticate?oauth_token=...
I load this url in my WebView
and I see the following page:
Here I'm stuck. When I click the Sign In
button, just this same page keeps loading up. Nothing else. When I click the Cancel
button however, I see the following page:
Only on this page when I click the Return to Fan League Beko BBL
button is my callback-url
invoked, with a denied
parameter which has my oauth_token
as its value. Anyone seen anything like this before and know what might be stopping my sign in request from being processed???
Update 1: I've tried the authentication url and the
Sign In
button from a desktop browser and it works as expected, processing the response and then invoking the callback-url. It's just failing when trying it in theWebView
of my Android app. I've tried it on multiple Android devices and tablets. JavaScript is enabled on myWebView
too so that's not it. Ideas most welcome. I'm out of ideas!Update 2: I've just done some debug-mode code-tracing on my
WebView
'sWebViewClient
and I'm seeing that when I click theSign In
button, theshouldOverrideUrlLoading(WebView webView, String url)
method is not called, but the following three methods are called (in order):onPageStarted(WebView view, String url, Bitmap favicon)
,onLoadResource(WebView view, String url)
,onPageFinished(WebView view, String url)
. Theurl
value these methods have is:https://api.twitter.com/oauth/authenticate
, i.e. theoauth_token
parameter has been stripped off the authenticate url. Maybe this is aPOST
request being treated as aGET
request and hence why this one same page keeps loading up? Any ideas what I can do to have thisSign In
button press processed properly?
Strangely my Twitter integration has started working. I didn't change my application code or my application's Twitter settings. I've noticed that where the Twitter authenticate page had a blue Sign In
button previously, it now has a blue Authenticate app
button. So I'm guessing something was changed/fixed on Twitter's end.