0

I've registered my app on the Twitter Developers site and got some OAuth credentials (Consumer Key, Consumer Secret, Request token URL etc).I have left the callback url blank.App is developed for both IOS and Android.Without callback url app is working in IOS but not working in android.When I have tried

requestToken = twitter
                    .getOAuthRequestToken(Constants.TWITTER_CALLBACK_URL);

I got the exception as

02-28 10:52:27.337: W/System.err(666): 401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync. 02-28 10:52:27.337: W/System.err(666): 02-28 10:52:27.337: W/System.err(666): 02-28 10:52:27.337: W/System.err(666):
/oauth/request_token 02-28 10:52:27.337: W/System.err(666): Desktop applications only support the oauth_callback value 'oob'

Then I have tried without callback url

requestToken = twitter
                    .getOAuthRequestToken();

And when I have tried to login I was redirected to a page (still within the web activity) congratulating me that I had granted my app access to my Twitter account and giving me a pin to enter where required and not redirecting to my app.

How can I login to twitter without callback url in Android? Thanks in advance.

user1767260
  • 1,543
  • 8
  • 26
  • 51
  • public static final String CALLBACK_URL = "twitterapp://connect"; have you tried this...?? – Ashish Jani Feb 28 '13 at 06:36
  • @AshishJani instead of Constants.TWITTER_CALLBACK_URL? I have not provided callback url while registration.so I am always getting the exception 401:Authentication credientials were missing – user1767260 Feb 28 '13 at 06:44
  • I have used CALLBACK_URL = "twitterapp://connect"; and its fine for me you may try it in your TWITTER_CALLBACK_URL – Ashish Jani Feb 28 '13 at 07:02
  • @AshishJani Have you provided any callback url while registering the app in Twitter – user1767260 Feb 28 '13 at 07:05

1 Answers1

0
  1. Create your own WebViewClient subclass.

2.Override shouldOverrideUrlLoading(WebView view, String url) method.

3.In shouldOverrideUrlLoading(), check if url.startsWith(YOUR_CALLBACK_URL) is true.

4.If true, retrieve "oauth_verifier" parameter from the URL and return true (true from shouldOverrideUrlLoading() prevents the WebView instance from loading the URL).

Get an access token using the value of the parameter obtained in the step 4. Your application can get control back from the WebView instance after the step 4.

If the above steps sound cumbersome, try TwitterOAuthView. Its usage is very simple. Just call

view.start(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL, true, listener); and receive the result via TwitterOAuthView.Listener interface defined as below.

void onSuccess(TwitterOAuthView view, AccessToken accessToken); void onFailure(TwitterOAuthView view, TwitterOAuthView.Result result); If true is given to TwitterOAuthView.start() method as the forth argument, TwitterOAuthView does not access the callback URL, and I think this behavior is what you want to implement. The source code, TwitterOAuthView.java, may be of help.

  • But I am not provided callback url while registration.Then how can I check with callback url? – user1767260 Feb 28 '13 at 06:49
  • see just try CALLBACK_URL = "twitterapp://connect" its enough to work . otherwise please create new credential and set call back URL. – AndroidEnthusiastic Feb 28 '13 at 08:41
  • I have tried requestToken = twitter .getOAuthRequestToken(Constants.TWITTER_CALLBACK_URL); where public static final String TWITTER_CALLBACK_URL = "twitterapp://connect"; and got exception 02-28 15:44:56.757: W/System.err(1599): 401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync. – user1767260 Feb 28 '13 at 10:16