Stack User 5674
Stack User 5674

Reputation: 1588

Twitter call back url not working in android

Now i try to Implement Twitter Integration in android using twitter4j library.Few months back I successfully implemented this using a dummy call back url like "PicPuzzle://tkxel".

But now Twitter changes its scheme and now not allow to create application with dummy URL.

Now the problem is after authentication It redirect to callbackurl But not return to application.

I specify the same url in application and registration page. I refered Problem in Callback in Twitter in Android and How I can call back in Android using OAuth for Twitter?. But these solutions are now not working because now twitter not allow to create application with dummy URL. Please help me to solve this problem.

Upvotes: 0

Views: 1808

Answers (2)

Chintan Soni
Chintan Soni

Reputation: 25267

Follow below steps:

  1. Go to Twitter Apps: https://apps.twitter.com/

  2. Then, Go to your app.

  3. Go to Settings Tab

  4. In section "Callback URLs", add the below line:

twittersdk://

  1. Click button "Update Settings" at the bottom. That's it.

Hope this works!

Upvotes: 1

Takahiko Kawasaki
Takahiko Kawasaki

Reputation: 18991

  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).
  5. 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.

Upvotes: 0

Related Questions