错误类型错误:this.onready不是来自Facebook的iOS应用程序的内部浏览器功能

问题描述 投票:2回答:1

我结合我的项目与Facebook授权https://developers.facebook.com/docs/facebook-login/web

翻车防护杆旁边会显示错误

类型错误:this.onready不是一个函数。 (在 'this.onready(一个)', 'this.onready' 是未定义的)

从facebook的IOS应用(版本172,171,170)的内部的浏览器的文件https://connect.facebook.net/en_US/sdk.js

请告诉我是什么问题,如何解决?

$.ajaxSetup({cache: true});
window.fbAsyncInit = function() {
    if(typeof FB != 'undefined'){
        FB.init({
          appId      : fb_app_id,
          cookie     : true,
          xfbml      : true,
          version    : 'v2.8'
        });

        FB.getLoginStatus(function(response) {
            if (response.status == 'connected') {
                    onLogin(response);
                } else {
                FB.login(function(response) {
                    onLogin(response);
                }, {scope: 'user_friends, email'});
            }
        });
    }
    else{
        Rollbar.debug("Not loaded base SDK");
        return false;
    }
};

(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement(s); js.id = id;
    js.src = "https://connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function checkLoginState() {

    if(typeof FB == 'undefined'){
        Rollbar.debug("FB is undefined. Was a problem loading the Facebook resources. Maybe your provider temporarily blocks this resource");
        return false;
    }

    FB.getLoginStatus(function(response) {
        onLogin(response);
    });
}
javascript facebook-javascript-sdk facebook-authorization
1个回答
0
投票

我们有同样的问题。 它看起来像有一个在Facebook的代码中的错误。里面的SDK -

                 var i = "fbNativeReady";
                 a = {
                    onready: function(a) {
                        __p && __p();
                        if (!h.nativeApp()) {
                            g.error("FB.Native.onready only works when the page is rendered in a WebView of the native Facebook app. Test if this is the case calling FB.UA.nativeApp()");
                            return
                        }
                        window.__fbNative && !this.nativeReady && ES("Object", "assign", !1, this, window.__fbNative);
                        if (this.nativeReady) a();
                        else {
                            var b = function b(c) {
                                window.removeEventListener(i, b), this.onready(a)
                            };
                            window.addEventListener(i, b, !1)
                        }
                    }
                };

你可以看到,事件监听器“B”未绑定的,所以当调度的事件“fbNativeReady”,听者会被调用在上下文中,意为“这”窗口,并在其上没有“onready”函数存在。 结合b键“这个”可以解决这个问题。

一种可能的解决方案可以是在一定的延迟后运行该代码,以避免具有fbNativeReady事件分派的代码被装载之后

© www.soinside.com 2019 - 2024. All rights reserved.