Making Facebook Login Work with an Android Webview

Google and Facebook Login (OAuth) in Webview App (popup function override needed?)

Google has blocked non-native WebView integrations from using oAuth as discussed in this thread, and changing the user agent no longer works. Your best bet here is to use the native integration.

The Facebook issue seems similar to the one discussed in this thread.

Android Webview and Facebook Login Not working

I was able to find a solution based on a previous question on stackoverflow.com

Making facebook login work with an Android Webview

Here is a link to my MainActivity : http://pastebin.com/KdzfhqDJ

Android WebView with Facebook Login

Well you can use the facebook SDK for your implementation.

basically in a webview they have shown their content like this

private void setUpWebView(int margin) {
LinearLayout webViewContainer = new LinearLayout(getContext());
mWebView = new WebView(getContext());
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
mWebView.setWebViewClient(new FbDialog.FbWebViewClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(mUrl);
mWebView.setLayoutParams(FILL);
mWebView.setVisibility(View.INVISIBLE);
mWebView.getSettings().setSavePassword(false);

webViewContainer.setPadding(margin, margin, margin, margin);
webViewContainer.addView(mWebView);
mContent.addView(webViewContainer);
}

private class FbWebViewClient extends WebViewClient {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Util.logd("Facebook-WebView", "Redirect URL: " + url);
if (url.startsWith(Facebook.REDIRECT_URI)) {
Bundle values = Util.parseUrl(url);

String error = values.getString("error");
if (error == null) {
error = values.getString("error_type");
}

if (error == null) {
mListener.onComplete(values);
} else if (error.equals("access_denied") ||
error.equals("OAuthAccessDeniedException")) {
mListener.onCancel();
} else {
mListener.onFacebookError(new FacebookError(error));
}

FbDialog.this.dismiss();
return true;
} else if (url.startsWith(Facebook.CANCEL_URI)) {
mListener.onCancel();
FbDialog.this.dismiss();
return true;
} else if (url.contains(DISPLAY_STRING)) {
return false;
}
// launch non-dialog URLs in a full browser
getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}

Facebook Login inside webpage on Webview not working

As of October 2013, facebook no longer allows apps to login via custom webviews.

Per this blog post, they want you to use the SDKs.

android facebook webview login does not bring user login

@takrishna. I managed to make FB login provided by website work in webview. The key point is that FB login javascript opens a new window when initializing a session for authentication with FB server. I create a new webview for FB login page. We need to keep website login page open which initialises the FB authentication, and once Fb authenticates user successfully, we close the new webview . After that website login webview receives callback and proceed user to login.

I agree that it is better to handle the FB login flow native for better user experience.



Related Topics



Leave a reply



Submit