检查用户是否是我的Facebook页面的粉丝? [英] Check if the user is a fan of my facebook page?
问题描述
我曾经在流行的代码中检查用户是否是我的页面的粉丝,而他在我的Facebook页面上。现在我想检查用户是否在我的网站上,是我的Facebook页面的粉丝。
I used to use the flowing code to check if the user is a fan of my page or not while he is on my facebook page. Now I want to check if the user is a fan of my facebook page while he is on my WEBSITE.
<?php
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["page"]["liked"])) {
echo "You are not a fan!";
} else {
echo "Welcome back fan!";
}
?>
我通过Facebook文档阅读,但我无法找到合适的答案。
帮助?
我不想用Facebook处理任何应用程序权限。我只能通过php来处理这个问题?
I read through the facebook documentation, but I was not able to find suitable answer. Help ? I do not want to deal with any application permissions with facebook. How can I approach this through only php ?
推荐答案
你不会得到页面
详细信息,如果访问应用程序不在页面选项卡。
You will not get page
details if visiting application not in Page Tab.
您可以通过简单的FQL查询来实现 page_fan
表(当然知道Facebook页面的id):
You may achieve that with simple FQL query to page_fan
table (knowing the id of the Facebook Page of course):
SELECT uid, page_id FROM page_fan WHERE uid=me() AND page_id=PAGE_ID
或者通过查询Graph API for 喜欢
连接用户
对象:
Or by querying Graph API for likes
connection of user
object:
https://graph.facebook.com/me/likes/PAGE_ID
这两种方式都需要用户授予的 user_likes
权限。
Both of those ways require user_likes
permission granted by user.
要获得相同的权限用户的朋友的详细信息请求 friends_likes
To get the same details for user's friends ask for friends_likes
permission and substitute me/me()
with friend id.
更新:(只是为了描述你在评论中提出的问题)
有些情况需要 user_likes
可能是不必要的,因为流的性质,如果你只需要知道该用户将/需要像某些URL和/或Facebook页面。
Update: (just to describe what you asked in comments)
There are cases that requiring user_likes
may be unnecessary due to nature of flow, if you only need to know that user will/need to like some URL and/or Facebook Page.
您可以通过订阅( FB.subscribe
)到 edge .create
事件,一旦用户喜欢页面(将不再喜欢 edge.remove
事件)将触发。
You may do so by subscribing (FB.subscribe
) to edge.create
event which will be triggered once user will like the page (for un-like there is edge.remove
event).
请注意,只有在用户不喜欢该内容之前,只有在 edge.create
仅在用户的动作。
Beware that this is only reliable in cases user didn't liked that content before since edge.create
only fired on time of user's action.
这篇关于检查用户是否是我的Facebook页面的粉丝?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!