如何确定 Facebook 用户是否“喜欢”某个页面
有没有办法通过 Facebook 目前提供的 API 来确定 Facebook 用户是否“喜欢”某个页面?
更新
我一直在尝试使用此代码通过 PHP 图形 API 使其工作一段时间。
$fbconfig['appid'] = '***';
$fbconfig['api'] = '***';
$fbconfig['secret'] = '***';
try {
include_once "facebook.php";
} catch(Exception $o) {
echo '<pre>';
print_r($o);
echo '</pre>';
}
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'cookie' => true,
));
$session = $facebook->getSession();
$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
d($e);
}
}
if($me) {
try {
$likes = $facebook->api('/me/likes');
} catch(Exception $o) {
d($o);
}
}
但是,即使我已登录,会话也始终为空。
显然,上述代码仅适用于 Facebook Connect“Canvas”应用程序,我从 Facebook 上的 FBML 选项卡调用此代码通过 AJAX 调用“页面”到我的服务器。
我不太熟悉 Facebook 的所有开发术语。
在我的情况下如何获得当前用户的“喜欢”?
Is there any way to determine if a Facebook user 'likes' a certain page with the API Facebook offers currently?
UPDATE
I have been trying to get this to work via the PHP graph API for a while now with this code.
$fbconfig['appid'] = '***';
$fbconfig['api'] = '***';
$fbconfig['secret'] = '***';
try {
include_once "facebook.php";
} catch(Exception $o) {
echo '<pre>';
print_r($o);
echo '</pre>';
}
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'cookie' => true,
));
$session = $facebook->getSession();
$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
d($e);
}
}
if($me) {
try {
$likes = $facebook->api('/me/likes');
} catch(Exception $o) {
d($o);
}
}
However, the session is always null, even though I am logged in.
Apparently, the above code is only good for Facebook Connect "Canvas" applications, I am calling this code from an FBML tab on a Facebook "Page" through an AJAX call to my server.
I'm not very familiar with all of the Facebook development terminology.
How can I get the current user's 'likes' in my situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有一种方法可以做到这一点,无需请求许可,也无需使用任何类型的 API。
如果您有 PHP:
您可以使用 $has_liked 来包装您的粉丝特定内容
替换
它非常有用且方便,因为请求许可是一种关闭。
There's a way to do that without requesting permission and without using any kind of API.
If you have PHP:
You can use $has_liked to wrap your fan-specific content
replaces
It's very useful and convenient, since asking for permission is a turn-off.
如果您使用图形 API,则提要中会有一个 Likes 对象,其中包含喜欢该特定帖子/提要项目的用户的 ID。
您还可以使用 FQL api 触发查询。
It you are using graph API, then there is a likes object in the feed which contains Id of the users who like that particular post/feed item.
Also you can fire query using FQL apis.
尝试使用 FQL。查看此页面,它可以让您测试 FQL 调用。
http://developers.facebook.com/docs/reference/rest/fql.query
SELECT user_id FROM like WHERE object_id="fb_id"
但将 fb_id 替换为您想知道有多少人喜欢的对象的 id。
Try using FQL. Check out this page, it lets you test FQL calls.
http://developers.facebook.com/docs/reference/rest/fql.query
SELECT user_id FROM like WHERE object_id="fb_id"
but replace fb_id with the id of the object you want to know how many people like.
要获得用户点赞,您需要
user_likes
权限。只需将权限添加到您的
fb:login-button
perms 属性中,下次用户登录时,系统会要求他授予您的应用程序访问新权限的权限。To get the user likes, you need the
user_likes
permission.Just add the permission to your
fb:login-button
perms attribute and next time the user logs-in, he will be asked to grant your application access to the new permission.