如何检查用户是否已经喜欢 Facebook 页面? [英] How to check IF user has ALREADY liked the facebook page?

查看:39
本文介绍了如何检查用户是否已经喜欢 Facebook 页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个赞按钮(供用户点赞 fb 粉丝页面).

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.

我非常希望得到以下帮助:

如果用户登录了 facebook 并且他们已经喜欢这个页面,我希望它显示你已经是粉丝了!"并显示内容.(而不是像按钮一样显示灰色)

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)

如果用户没有登录到 facebook 并且他们点击了赞"按钮,我希望它显示你已经是粉丝了!"并显示内容.(而不是像按钮一样显示灰色)

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)

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

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

推荐答案

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

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;
}

这篇关于如何检查用户是否已经喜欢 Facebook 页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆