简体   繁体   English

安装了Facebook本机应用程序后,服务器端Facebook登录是否无法在“ cordova android应用程序”上运行?

[英]Server-side Facebook login stops working on a “cordova android app” when facebook native app is installed?

Problem: Facebook login stops working when a Facebook native app is installed on android device 问题:在Android设备上安装Facebook本机应用程序后,Facebook登录停止工作

Entities involved: 1. Facebook login 2. Cordova app 3. InAppBrowser 4. Android (version 5.1) 5. Facebook native app 涉及的实体:1. Facebook登录2. Cordova应用程序3. InAppBrowser 4. Android(5.1版)5. Facebook本机应用程序

Observation: 观察:

  1. UI :- 使用者介面:

A blank white screen displayed when I click on my login button 当我单击登录按钮时,显示空白的白色屏幕

  1. Logs :- 日志:-

Two log excerpts are provided (at the end). 提供了两个日志摘录(最后)。 The first one is quite standard (the one during app initialization). 第一个是非常标准的(在应用程序初始化期间)。 In the second log, the InAppBrowser's loadstart event is immediately followed by a loadstop event . 在第二个日志中,InAppBrowser的loadstart事件紧随其后是loadstop事件。 This leads to a blank page. 这导致空白页。

  1. Code used :- 使用的代码:-

The code used is derived from OpenFb ( https://github.com/ccoenraets/OpenFB ) . 使用的代码来自OpenFb( https://github.com/ccoenraets/OpenFB )。 The code is provide at the end of this question (below the logs). 该问题末尾(日志下方)提供了代码。

  1. Questions :- 问题:-

a) Why is 'loadstop' called immediately after 'loadstart' (without any lag) - when facebook native app is installed? a)为什么在“ loadstart”之后立即调用“ loadstop”(没有任何滞后)-安装了Facebook本机应用程序后?

b) Does it have anything to do with deeplinking of facebook app? b)与Facebook应用程序的深层链接有关吗?

c) Possible resolutions would be appreciated. c)可能的解决方案将不胜感激。

PS... other similar questions on SO don't have answers. PS ...其他类似的问题也没有答案。


Appendix (Log and Code) 附录(日志和代码)

Log from app initialization (nothing unique here though) 从应用初始化记录(尽管这里没有什么独特之处)

    I/WebViewFactory(20666): Loading com.google.android.webview version 57.0.2987.132 (code 298713250)
    I/art     (20666): Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
    ...
    I/art     (20666): Rejecting re-init on previously-failed class
    ...
    D/WebView (20666): WebView<init>
    D/WebView (20666): setInitialScale=0
    D/SystemWebViewEngine(20666): CordovaWebView is running on device made by: OPPO
    D/WebView (20666): addJavascriptInterface=_cordovaNative
    D/CordovaWebViewImpl(20666): >>> loadUrl(file:///android_asset/www/index.html)
    D/WebView (20666): loadUrl=file:///android_asset/www/index.html
    D/WebView (20666): onResume
    ...
    D/CordovaWebViewImpl(20666): onPageDidNavigate(file:///android_asset/www/index.html)
    ...
    D/CordovaWebViewImpl(20666): onPageFinished(file:///android_asset/www/index.html#/)iew (20666): evaluateJavascript=cordova.callbackFromNative('InAppBrowser114205225',true,1,[{"type":"loadstop","url":"https:\/\/www.halfchess.com\/auth\/facebook?r=https%3A%2F%2Fwww.halfchess.com%2F"}],true);

Log when I click LOGIN button. 单击“登录”按钮时登录。

    D/SystemWebChromeClient(20666): file:///android_asset/www/bundle.js: Line 76246 : LOGIN_ATTEMPT
    D/WebView (20666): WebView<init>
    D/WebView (20666): loadUrl=https://www.halfchess.com/auth/facebook?r=https%3A%2F%2Fwww.halfchess.com%2F
    D/WebView (20666): evaluateJavascript=cordova.callbackFromNative('InAppBrowser114205225',true,1,[""],true);
    V/InputMethodManager(20666): onWindowFocus: android.webkit.WebView{11dadeb5 VFEDHVC. .F....ID 0,0-720,1244 #6} softInputMode=16 first=true flags=#0
    V/InputMethodManager(20666): START INPUT: android.webkit.WebView{11dadeb5 VFEDHVC. .F....ID 0,0-720,1244 #6} ic=null tba=android.view.inputmethod.EditorInfo@604488f controlFlags=#105
    D/WebView (20666): evaluateJavascript=cordova.callbackFromNative('InAppBrowser114205225',true,1,[{"type":"loadstart","url":"https:\/\/www.halfchess.com\/auth\/facebook?r=https%3A%2F%2Fwww.halfchess.com%2F"}],true);
    D/SystemWebChromeClient(20666): file:///android_asset/www/bundle.js: Line 39091 : loadHandler: https://www.halfchess.com/auth/facebook?r=https%3A%2F%2Fwww.halfchess.com%2F
    D/WebView (20666): evaluateJavascript=cordova.callbackFromNative('InAppBrowser114205225',true,1,[{"type":"loadstop","url":"https:\/\/www.halfchess.com\/auth\/facebook?r=https%3A%2F%2Fwww.halfchess.com%2F"}],true);

The Code used in app. 应用中使用的代码。

    function cordovaFbLogin(redirectUrl) {
      const promise = new Promise((resolve, reject) => {
        //console.log('Inside cordovaFbLoginApi');
        let loginWindow = window.open(
                  `${fbLoginUrl}?r=${redirectUrl}`,
                  '_blank',
                  'location=no,hardwareback=no,clearsessioncache=yes');

        const startTime = new Date().getTime();
        let isPending = true;
        let visitedFacebook = false;

        const loadHandler = (event) => {
          const url = event.url;
          console.log('loadHandler: ' + url);

          if (url.indexOf('https://www.facebook.com') === 0) {
            visitedFacebook = true;
            return;
          }

          // NOTE: redirection sequence is a follows
          // facebook domain --> Halfchess --> redirectUrl
          // We close the window at '2nd step' (see below)
          if (url.indexOf('https://halfchess.com') === 0 && visitedFacebook) {
              // exit when the browser redirects back to us
            if (url.indexOf('code=') > 0) {
              // we have the cookie - make next API call or reject
              isPending = false;
              resolve();
            } else if (url.indexOf('error=') > 0) {
              isPending = false;
              reject();
            }
          }

          if (!isPending) {
            // in the Cordova app, and trying to close it while it's animating
            // generates an exception. Wait a little...
            const timeout = 600 - (new Date().getTime() - startTime);
            setTimeout(() => {
              loginWindow.close();
            }, timeout > 0 ? timeout : 0);
          }

        };

        const loadError = (error) => {
          console.log('fbLogin window - load error')
          console.log(error);
        }

        const exitHandler = () => {
          console.log('fbLogin window - exit');
          loginWindow.removeEventListener('loaderror', loadError)
          loginWindow.removeEventListener('loadstart', loadHandler)
          loginWindow.removeEventListener('exit', exitHandler)
          loginWindow.close();
          loginWindow = undefined;
        };

        loginWindow.addEventListener('loadstart', loadHandler);
        loginWindow.addEventListener('loaderror', loadError);
        loginWindow.addEventListener('exit', exitHandler);
      });
      return promise;
    }

I finally used a solution where I would detect if I have a facebook app (the plugin to use for the same is cordova-plugin-appavailability) and then follow one of the below flows :- 我终于使用了一种解决方案,可以检测到我是否有一个Facebook应用程序(用于该应用程序的插件是cordova-plugin-appavailability),然后按照以下流程之一进行操作:-

  1. If I have a native fb app, then use cordova-plugin-facebook4 . 如果我有本地fb应用程序,请使用cordova-plugin-facebook4。 The client receives the token from facebook and passes it to the server (I created a new route) 客户端从Facebook接收令牌并将其传递到服务器(我创建了一条新路由)

  2. If I don't have a native fb app, then I use the function I have written above (or a variation of the same - refactored it since I last posted). 如果我没有本机fb应用程序,那么我将使用上面编写的功能(或同一功能的变体-自上次发布以来对其进行了重构)。

We weed to implement both the approaches because (1) will not work if there is no facebook native app and (2) will not work if there is a facebook native app on the phone. 我们对两种方法都进行了除草,因为(1)如果没有Facebook本机应用程序将不起作用,并且(2)如果电话上存在Facebook本机应用程序将不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Facebook应用程序在服务器端登录 - Server-side login with Facebook app Ionic 4:安装本机 facebook 应用程序时,使用 android 登录 facebook 失败 - Ionic 4: failed facebook login with android when the native facebook app is installed Android facebook 登录不适用于已安装的 Facebook 应用程序 - Android facebook login not working with installed Facebook app Facebook Android SDK仅在安装本机应用程序时有效 - Facebook Android SDK only working when native app installed Android Facebook登录无法与安装的本机Facebook一起使用 - android facebook login is not working with native facebook installed 安装本机Facebook应用程序后,Facebook示例会话登录应用程序不起作用 - Facebook Sample Session Login Applicatiom not working when Native Facebook app installed 使用 Facebook 的 Android 应用程序登录不适用于已安装的 Facebook 应用程序 - Android Application Login with Facebook is not working with Facebook App installed 如果安装了本地Facebook应用,则无法使用Facebook集成 - Facebook integration in not working if native facebook app is installed android Facebook应用程序安装在android中的Facebook登录问题 - Facebook Login issue when facebook app is installed in android 安装Facebook应用后,Facebook登录中断 - Facebook login breaks when Facebook app is installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM