【问题标题】:How to check whether user already likes a page or not using FB.api?如何使用 FB.api 检查用户是否已经喜欢一个页面?
【发布时间】:2015-09-16 15:35:08
【问题描述】:

我使用下面的代码来检查用户是否已经喜欢该页面。

window.fbAsyncInit = function () {
               FB.init({
                appId: 'XXXXXXXXXXX', // App ID
                channelUrl: '//' + window.location.hostname + '/channel', // Channel File
                status: true, // check login status
                cookie: true, // enable cookies to allow the server to access the session
                oauth: true,
                xfbml: true  // parse XFBML
            });

FB.getLoginStatus(function (response) {
      if (response && response.authResponse) {
         getAPIResponse();
      }
      else {
          FB.login(function (response) {
              if (response.authResponse) {
                   getAPIResponse();
              }
              else {
                document.getElementById('MainView').style.display = 'none';
                   }
          });
                }
            });
};

// 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));

 function getAPIResponse() {
         FB.api("me/likes/XXXXXXXXXXXXX", function (response) {
                if (response.data.length == 1) {
                    document.getElementById('MainView').style.display = 'block';
                } else {
                    document.getElementById('MainView').style.display = 'none';
                    alert("Like our Page to show Calendar");
                }
            });
  }

上面的代码以前可以正常工作。但是现在 response.data.length 总是返回零。如何解决上述问题?

【问题讨论】:

    标签: facebook facebook-graph-api facebook-like facebook-page fbml


    【解决方案1】:

    您似乎没有请求使用类似信息所必需的user_likes 权限。

    此外,从您的代码示例中,您似乎“点赞”了 Facebook 不允许的内容,因此可能不允许您通过登录审查,这是使用user_likes 所必需的。

    【讨论】:

    • 是否有必要提交我的应用以获得 Facebook 的登录审核批准才能访问 user_likes 信息?
    • 是的,请看一下文档,这些问题大多会自行回答:developers.facebook.com/docs/facebook-login/review
    • 此审核流程是最近实施还是从一开始就实施,因为此编码以前有效?
    • 我可以在我的代码中使用低于 v2.0 的代码来让我的代码像以前一样工作 window.fbAsyncInit = function () { FB.init({ appId: 'XXXXXXXXXXX', // App ID channelUrl: '//' + window.location.hostname + '/channel', // Channel File status: true, // 检查登录状态 cookie: true, // 启用cookies以允许服务器访问会话 oauth: true, version : 'v1.X', xfbml: true // 解析 XFBML });
    • 不,自 2015 年 5 月 1 日起 v1.0 已消失:developers.facebook.com/docs/apps/api-v1-deprecation
    猜你喜欢
    • 2013-08-14
    • 2011-11-15
    • 2011-10-13
    • 1970-01-01
    • 2011-05-20
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    相关资源
    最近更新 更多