Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Facebook access token in android app webview

Tags:

In my application, the user opens a WebView to the mobile versions of facebook profile page (http://m.facebook.com/some_page). My problem is that when opening the WebView, the user is required to enter username and password for Facebook. Since I already have a Facebook access token through FB SDK, and the user might have installed the Facebook application, I assume there is some way to skip this annoying phase of signing into Facebook when opening the WebView.

In other words, how do I use the access token that I already have in my application's WebView?

like image 590
joy Avatar asked Oct 16 '12 02:10

joy


People also ask

How can I get Facebook token in Android?

To get the Client Access Token for an app, do the following: Sign into your developer account. On the Apps page, select an app to open the dashboard for that app. On the Dashboard, navigate to Settings > Advanced > Security > Client token.

Does Facebook use WebView?

Deprecating Facebook Login support on Android WebViewsBeginning October 5, 2021, Facebook Login will no longer support using Android embedded browsers (WebViews) for logging in users.


1 Answers

From my understanding, you can't. The access token you get for your app can only be used in conjunction with the API credentials of your App. I.e. the access token only works in calls that also contain your app's key and secret. Even if you could find a way to pass these into a WebView (which is most probably not covered by FB's Data Policies), you'd probably have to make the WebView pretend to use the Android SDK (because FB would check the call's source). That's why I suggest you can't.

You also cannot have the WebView use the user's cookies he might have in his stock browser, as each WebView has it's own context for security reasons.

If you're frequently using a WebView for FB in your app, you might be able to pull the auth cookie out of the first WebView, and then insert it into subsequent instances using CookieSyncManager. Or you could save the instance state of the first WebView and then reuse it. These are just ideas that might or might not work; I haven't checked them out.

like image 113
domsom Avatar answered Oct 12 '22 22:10

domsom