1

这是我的代码:

    <div id="fb-root"></div>

<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : '',                        // App ID from the app dashboard
      channelUrl : 'http://.php', // Channel file for x-domain comms
      status     : true,                                 // Check Facebook Login status
      xfbml      : true                                  // Look for social plugins on the page
    });

    // Additional initialization code such as adding Event Listeners goes here
    FB.api('me/likes/',function(response) {
        if( response.data ) {
            if( !isEmpty(response.data) )
                alert('You are a fan!');
            else
                alert('Not a fan!');
        } else {
            alert(response);
            alert('ERROR!');
        }
    });
  };

  // Load the SDK asynchronously
  (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 = "//connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));



// function to check for an empty object
function isEmpty(obj) {
    for(var prop in obj) {
        if(obj.hasOwnProperty(prop))
            return false;
    }

    return true;
}
</script>

但是我返回了错误字符串......我做错了什么?

4

2 回答 2

9

要获取用户是否是该页面的粉丝,您可以执行以下操作:

FB.api({
    method:     'fql.query', 
    query:  'SELECT uid FROM page_fan WHERE uid=user_id AND page_id=page_id'
}, function(resp) {
    if (resp.length) {
        alert('A fan!')
    } else {
        alert('Not a fan!');
    }
}
);

您可以在此处阅读更多相关信息:http: //www.masteringapi.com/tutorials/facebook-api-check-if-a-user-is-fan-of-a-facebook-page/20/

类似的问题:

Facebook Javascript,如何检测用户是否是我的 Facebook 页面的粉丝?在我的网站上?

于 2013-04-09T13:25:10.237 回答
-1

我没有执行登录和令牌访问! https://developers.facebook.com/docs/howtos/login/getting-started/

于 2013-04-09T13:31:29.603 回答