如何检查用户是否已经喜欢该 Facebook 页面?

发布于 2024-12-04 09:53:18 字数 1202 浏览 0 评论 0原文

我的网站上有一个喜欢按钮(供用户喜欢 Facebook 粉丝页面)。

如果用户单击“喜欢”,我会检查事件是否已被触发(事件订阅),然后向他们显示一些内容。

我非常感谢您提供以下帮助:

如果用户登录了 facebook 并且他们已经喜欢该页面,我希望它显示“您已经一个粉丝!”并显示内容。 (而不是显示灰色的“点赞”按钮)

如果用户未登录 facebook 并且他们点击了“点赞”按钮,我希望它显示“您是已经是粉丝了!”并显示内容。 (而不是显示灰色的类似按钮)

编辑:伙计们,我对此进行了研究,并发现了类似的问题,但不完全是我所追求的。也许我错了,但如果有人可以提供一个描述我的确切问题的链接,那么它会比问题上的“-”更有帮助。我已检查以下内容:
检查用户是否连接到 Facebook,然后检查他是否喜欢某个页面
Facebook Like Box:如何检测是否用户已经喜欢该页面?
当页面已被喜欢时 Facebook LIKE 按钮隐藏用户
如何检查是否用户喜欢该页面或未使用 php/javascript
检查用户是否已经喜欢粉丝专页

I have a like button on my website (which is for users to like the fb fan page).

If the user clicks like, I check to see if the even has been fired (event subscribe), and then display some content to them.

What I would really appreciate help with is the following:

If the user is logged in to facebook AND they already like the page, I want it to display "You're already a fan!" and show the content. (rather than displaying the greyed out like button)

OR

If the user is not logged in to facebook and they click the like button, I want it to display "You're already a fan!" and show the content. (rather than displaying the greyed out like button)

edit: Guys, I've researched this on SO and have found similar questions but not quite what I'm after. Maybe I'm mistaken but if someone can provide a link to one which describes my exact problem, it would be a lot more helpful than a - on the question. I have checked the following:
Check if the user is connected to facebook and then check if he liked a page
Facebook Like Box: How to detect if user already liked the page?
Facebook LIKE button hiding when page is already LIKED by user
How to check whether user has liked the page or not using php/javascript
Check if user already likes fanpage

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦忆晨望 2024-12-11 09:53:18

如果您使用 facebook php API。我想出了这个简短的函数,您可以将其包含在 BaseFacebook 类的 base_facebook.php 文件中。

public function userIsFan() {
    $sr = $this->getSignedRequest();
    if($sr && is_array($sr)){
        if(array_key_exists('page', $sr)){
            return $sr['page']['liked'] == 1;
        }
    }
    return 0;
}

If you use the facebook php API. i've came up with this short function that u can include inside the base_facebook.php file into the class BaseFacebook.

public function userIsFan() {
    $sr = $this->getSignedRequest();
    if($sr && is_array($sr)){
        if(array_key_exists('page', $sr)){
            return $sr['page']['liked'] == 1;
        }
    }
    return 0;
}
谁许谁一生繁华 2024-12-11 09:53:18

确保您使用的是 xfbml,
这个对我有用

FB.Event.subscribe('auth.authResponseChange', function(response) {
        FB.api('/me/likes/[page_id]',
          function(response) {
              //console.log(response); - see what the response is on your console.
              if(response.data[0])
                //use script to display your content alert("Liked");
              else
                // just do nothing, display like button alert("Not yet liked");
          }
        );

    });

page_id 将是 id 而不是您页面的名称,要查找 id,只需访问 http://graph.facebook.com/[your fb page name]

希望如此将来帮助某人。

Make sure you are using xfbml,
this one works for me

FB.Event.subscribe('auth.authResponseChange', function(response) {
        FB.api('/me/likes/[page_id]',
          function(response) {
              //console.log(response); - see what the response is on your console.
              if(response.data[0])
                //use script to display your content alert("Liked");
              else
                // just do nothing, display like button alert("Not yet liked");
          }
        );

    });

page_id will be the id not the name of your page, to find out the id, just visit http://graph.facebook.com/[your fb page name]

hope this helps someone in the future.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文