【问题标题】:Facebook: FB.apiClient TypeError: $wnd.FB.Facebook is undefined" why this error occures?Facebook: FB.apiClient TypeError: $wnd.FB.Facebook is undefined" 为什么会出现这个错误?
【发布时间】:2010-06-20 15:20:17
【问题描述】:

Facebook 面临一个问题。 我们在我们的网络应用程序中集成了 FB,当用户在我们的网络应用程序中通过 fconnect 登录时,他只需提供他的电子邮件 id 就可以在我们的系统中注册(仅第一次)。对于普通用户来说,很少有用户 i/p 在我们的系统中注册

我们的 web 应用程序是用 java [GWT2.0] 开发的。

问题是当 FACEBOOK 或普通用户在我们的网络应用程序中通过 FB 登录时。(一次 1 个)

当用户刷新页面时,FB弹出窗口出现消息

“调试:加载 FB.apiClient 时出现异常类型错误:$wnd.FB.Facebook 未定义”

或有时 $wnd.FB.Facebook.apiClient is null 发生

我们收到 3 次以上错误[弹出]消息。

我们在 html 页面中使用了以下脚本

仅在我们的网络应用程序的 1 个页面中,即我们显示用户信息的 UserHome 页面。 在该页面上仅出现上述错误消息

我们在控制器类[单例类]中使用了以下 GWT 代码 [来自 Gwittit]

/** * 加载第一页上的所有数据时调用函数。 * * */ 公共无效 notifyFinishedLoadinPage() { FacebookConnect.waitUntilStatusReady(新 RenderAppWhenReadyCallback());

}

私人 MyLoginCallback loginCallback = new MyLoginCallback();

class MyLoginCallback implements LoginCallback {

    public void onLogin() {
        isFacebookSign = true;
        fbLoggedInUserId = ApiFactory.getInstance().getLoggedInUser();

        for (FacebookObserver Observer : facebookObservers) {
            Observer.notifyFacebookLogin(true);
        }
    }
}

public void publishStream(final FacebookObserver fbObserver) {
    FacebookConnect.init(FacebookConstants.FACEBOOK_API_KEY,

"xd_receiver.htm", loginCallback);

    FacebookConnect.requireSession(new

AsyncCallback() {

        public void onFailure(Throwable caught) {
            Window.alert("Require session failed: " + caught);
            GWT.log("Require session failed: " + caught, null);
        }

        public void onSuccess(Boolean isLoggedIn) {
            if (isLoggedIn) {
                for (FacebookObserver Observer :

facebookObservers) { 观察者.notifyPublishStream(); } } } });

}

public void facebookConnection() {
    FacebookConnect.init(FacebookConstants.FACEBOOK_API_KEY,

"xd_receiver.htm", loginCallback); //服务器 FacebookConnect.requireSession(新 AsyncCallback() {

        public void onFailure(Throwable caught) {
            GWT.log("Require session failed: " + caught, null);
        }

        public void onSuccess(Boolean isLoggedIn) {
            if (loginCallback != null && isLoggedIn) {
                loginCallback.onLogin();
            } else {
                //User not logged in
            }
        }
    });
}

/**
 * Fired when we know users status
 */
private class RenderAppWhenReadyCallback implements

异步回调 {

    public RenderAppWhenReadyCallback() {
        FacebookConnect.init(FacebookConstants.FACEBOOK_API_KEY,

"xd_receiver.htm", loginCallback); //服务器 }

    public void onFailure(Throwable caught) {
        Window.alert("Unable to login through Facebook: " + caught);
    }

    public void onSuccess(ConnectState result) {
        if (result == ConnectState.connected) {
            isFacebookSign = true;

            for (FacebookObserver Observer : facebookObservers) {
                Observer.notifyFacebookLogin(true);
            }

            //History.newItem(HistoryConstants.USERHOME_PAGE_HISTORY_TOKEN);
        } else {
            //rightSideFlexTable.clearCell(0, 0);
            //rightSideFlexTable.setWidget(0, 0,

脸书面板); isFacebookSign = false;

        }
    }
};

现在我们无法找到解决此问题的方法。

谁能帮助我们尽快解决这个问题

希望最好的合作

【问题讨论】:

  • 你能提供更多关于你的问题的细节吗?您是否尝试使用 GWT 的常规 JS Facebook 库?如果有,是哪一个,代码是什么样的?
  • @jason Hall 我们在 html 页面中使用了以下脚本 static.ak.connect.facebook.com/js/api_lib/v0.4/…"> 你能解释一下为什么会出现这个错误吗?
  • 您可以使用 Firebug 或 Chrome 的开发工具来检查脚本是否正在加载?尝试使用控制台调用apiClient 上的方法。您是否尝试从 GWT 调用此代码?你能发布那个代码吗?
  • @jason hall 我添加了 GWT 代码供您参考

标签: gwt facebook


【解决方案1】:

我们找到了上述问题的解决方案。

Facebook(登录)加载需要一些时间。

在我们的网页中,我们获取 fb 详细信息,例如 fb 用户登录 ID、图像等。 所以在页面加载时我们得到所有值 null 因为 facebook 没有正确加载 所以我们得到 $wnd.FB.Facebook.apiClient is null

调试:加载 FB.apiClient 时出现异常类型错误:$wnd.FB.Facebook 未定义"

为了解决这个问题,我们编写了一个方法,当用户刷新页面或 Facebook 加载正确完成后调用。

public void notifyFacebookLogin(boolean isLogin) {

长 fbLoggedInUserId = ApiFactory.getInstance().getLoggedInUser();

如果 (fbLoggedInUserId != null) {

if (globalEndUserInfo == null) {
    globalEndUserInfo = new EndUserInfo();
    globalEndUserInfo.setFbLoggedInUserId(fbLoggedInUserId);
  }

}

// 处理 FB 相关对象的代码

}

现在当用户刷新页面或 fb 加载需要时间时不会显示错误消息

通过这种方式我们解决了我们的问题。 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-15
    • 2018-08-05
    • 2020-03-03
    • 2013-08-13
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    相关资源
    最近更新 更多