1

我想在自定义页面选项卡单击时从 Facebook 获取页面 ID。这是代码,我正在使用。这是从 Facebook 获取页面 id 的正确方法吗?我可以使用此代码获取访问令牌和用户 ID 值。任何帮助是极大的赞赏。

  window.fbAsyncInit = function () {
     FB.init({
        appId: 'xxxxxxxxx',
        status: true, 
        cookie: true, 
        xfbml: true  
    });

    FB.Event.subscribe('auth.authResponseChange', function (response) {
        // Here we specify what we do with the response any time this event occurs. 
        if (response.status === 'connected') {                                                                           
        } else if (response.status === 'not_authorized') {
            //FB.login();
        } else {
            //FB.login();
        }
    });
};
// Load the SDK asynchronously
(function (d) {
    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);
} (document));

$('.btnclick').click(function () {
    fblogin();
});

function fblogin() {           
    //FB.login();
    FB.login(function (response) {
        if (response.authResponse) {                
            var sq = FB.getAuthResponse()['signedRequest']; 
            var data = sq.split('.')[1];
            data = JSON.parse(atob(data));
            alert(data);                
        } else {
            alert('User cancelled login or did not fully authorize.');
        }
    }, { scope: 'user_location,user_hometown,user_photos,friends_photos,friends_location,friends_hometown,email,user_likes,publish_actions,manage_pages', display: 'popup' });
}
4

1 回答 1

1

第 1 步:获得 manage_pages 权限

第2步 :

    FB.api('/me?fields=accounts', function (apiResponse) {
       //apiResponse will have page id inside apiResponse.accounts.data
    });

'/me?fields=accounts' - account 用于获取 fb pageid

用于获取页面详细信息表单页面 id

FB.api('/ page id ?fields=about,albums{link},photos{link},phone,location,single_line_address', function (page) {
                //To get page details from page id
            });
于 2016-03-28T07:24:23.133 回答