facebook登录API调用计时

facebook log-in API calls timing

本文关键字:调用 API 登录 facebook      更新时间:2023-09-26

找不到足够相似的问题,所以我会问。

我正在尝试在我的页面上使用facebook登录。

我做的每件事都按照开发者的指导。但是,我不确定什么时候可以开始呼叫FB.API呼叫。用户何时通过身份验证?我怎么知道这个手术是什么时候做的?

<script>
    window.fbAsyncInit = function () {
        FB.init({
            appId: 'someID', // App ID
            channelUrl: '//www.domain.com/channel.html', // Channel File
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true  // parse XFBML
        });
    };
    // Load the SDK Asynchronously
    (function (d) {
        var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; }
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        d.getElementsByTagName('head')[0].appendChild(js);
    } (document));
</script>

现在我想叫这个

    FB.api('/me', function (response) {
        facebookUser = response; 
        alert('Your name is ' + response.name);
    });

但不确定写入时间是什么时候。无论放在哪里,我都会得到未定义:/

您将需要运行FB.getLoginStatus()(https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/)在发送用户使用FB.login()登录之前,或者如果用户已登录,则调用FB.api()方法。