簡體   English   中英

安裝了Facebook本機應用程序后,服務器端Facebook登錄是否無法在“ cordova android應用程序”上運行?

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

問題:在Android設備上安裝Facebook本機應用程序后,Facebook登錄停止工作

涉及的實體:1. Facebook登錄2. Cordova應用程序3. InAppBrowser 4. Android(5.1版)5. Facebook本機應用程序

觀察:

  1. 使用者介面:

當我單擊登錄按鈕時,顯示空白的白色屏幕

  1. 日志:-

提供了兩個日志摘錄(最后)。 第一個是非常標准的(在應用程序初始化期間)。 在第二個日志中,InAppBrowser的loadstart事件緊隨其后是loadstop事件。 這導致空白頁。

  1. 使用的代碼:-

使用的代碼來自OpenFb( https://github.com/ccoenraets/OpenFB )。 該問題末尾(日志下方)提供了代碼。

  1. 問題:-

a)為什么在“ loadstart”之后立即調用“ loadstop”(沒有任何滯后)-安裝了Facebook本機應用程序后?

b)與Facebook應用程序的深層鏈接有關嗎?

c)可能的解決方案將不勝感激。

PS ...其他類似的問題也沒有答案。


附錄(日志和代碼)

從應用初始化記錄(盡管這里沒有什么獨特之處)

    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);

單擊“登錄”按鈕時登錄。

    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);

應用中使用的代碼。

    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;
    }

我終於使用了一種解決方案,可以檢測到我是否有一個Facebook應用程序(用於該應用程序的插件是cordova-plugin-appavailability),然后按照以下流程之一進行操作:-

  1. 如果我有本地fb應用程序,請使用cordova-plugin-facebook4。 客戶端從Facebook接收令牌並將其傳遞到服務器(我創建了一條新路由)

  2. 如果我沒有本機fb應用程序,那么我將使用上面編寫的功能(或同一功能的變體-自上次發布以來對其進行了重構)。

我們對兩種方法都進行了除草,因為(1)如果沒有Facebook本機應用程序將不起作用,並且(2)如果電話上存在Facebook本機應用程序將不起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM