gpt4 book ai didi

javascript - Facebook API - 检测 session 是否处于事件状态

转载 作者:行者123 更新时间:2023-11-30 06:41:08 26 4
gpt4 key购买 nike

我确定我只是忽略了 Facebook API 文档中的某些内容。基本上,在我加载 FB Graph 之后,我需要知道 session 是否处于事件状态......我不能简单地假设他们已注销并且如果他们在“auth.statusChange”后登录则简单地重新呈现事件被触发。我需要马上知道。

下面是我用过的代码。最重要的是 FB.getLoginStatus/getAuthResponse/getAccessToken 不像我期望的那样工作;本质上,它在调用时指示它们是登录还是注销。

(function(d) {    // Create fb-root    var fb_root = document.createElement('div');        fb_root.id = "fb-root";        document.getElementsByTagName('body')[0].appendChild( fb_root );    // Load FB Async    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];    if (d.getElementById(id)) {return;}    js = d.createElement('script'); js.id = id; js.async = true;    js.src = "//connect.facebook.net/en_US/all.js";    ref.parentNode.insertBefore(js, ref);    // App config-data    var config = {        appId : XXXX,        cookie: true,        status: true,        frictionlessRequests: true    };    window.fbAsyncInit = function() {        // This won't work.        // I can't assume they're logged out and rely on this to tell me they're logged in.        FB.Event.subscribe('auth.statusChange', function(response) {});        // Init        FB.init(config);        // These do not inidicate if the user is logged out :(        FB.getLoginStatus(function(response) { });        FB.getAuthResponse(function(response) { });        FB.getAccessToken(function(response) { });    };}(document));

非常感谢任何帮助。 :)

最佳答案

感谢您的帮助,但我在另一篇文章中找到了答案:https://stackoverflow.com/a/7765144/560686

显然,当您仍处于沙盒模式时,FB.getLoginStatus() 将仅在用户登录时触发回调,而不是在用户注销时触发。为了让它工作,我必须禁用沙盒模式。 :)

关于javascript - Facebook API - 检测 session 是否处于事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11236578/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com