Android and Twitter4j: Handling OAuth with a Webview widget?

I have a working twitter4j implementation, but the OAuth process for authorizing the application leaves the Android web browser behind the application. I would like to try to implement my own webview in a running activity in order to finish () this or at least clean up after my application. The problem is that now I need to figure out how to return authURL to my main activity.

What is the best way to return authURL? I have subclassed the webview widget and am experimenting with the ability to return authURL to onPageFinished (), but not quite there yet.

private class myWebViewClient extends WebViewClient { @Override public void onPageFinished (WebView view, String url) { Log.d (TAG, "onPageFinished"); super.onPageFinished (view, url); if (url.contains (TwitterLibActivity.CALLBACK_URL) == true) { /* mRetIntent = new Intent(); mRetIntent.putExtra ("verifed", url); setResult (RESULT_OK, mRetIntent); */ Log.d (TAG, "have auth url:" + url); finish(); } } @Override public boolean shouldOverrideUrlLoading (WebView view, String url) { Log.d (TAG, "myWebViewClient url:" + url); //return super.shouldOverrideUrlLoading (view, url); return (false); } } 
+6
source share
3 answers

I recently discovered that this article only works with twitter4j without singpost, this work with webview and can help you: http://davidcrowley.me/?p=410

Hi

+5
source

TwitterOAuthView is a subclass of WebView dedicated to Twitter OAuth on Android using twitter4j.

Twitter OAuth View for Android with twitter4j
http://darutk-oboegaki.blogspot.jp/2012/07/twitter-oauth-view-for-android-using.html

Since it is implemented as a subclass of View, it can be easily integrated into the Android hosting system. This fact makes TwitterOAuthView an easily changeable user interface component.

Its use is very simple. Just call the start () method

 // Start Twitter OAuth process. Getting a request token, opening Twitter's // authorization page, and getting an access token are performed. view.start(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL, true, listener); 

and get its result through the TwitterOAuthView.Listener interface.

 // Definition of TwitterOAuthView.Listener interface. void onSuccess(TwitterOAuthView view, AccessToken accessToken); void onFailure(TwitterOAuthView view, TwitterOAuthView.Result result); 

An example implementation of an Activity using TwitterOAuthView can be found on GitHub TwitterOAuthView .

+5
source

Here is a good example of twitter and android integration code, I myself used it with changes as needed ...

0
source

Source: https://habr.com/ru/post/909103/


All Articles