2

我们如何检查用户是否喜欢 facebook 应用程序?

我正在尝试创建一个 Facebook 应用程序,其中有两个不同的页面,如果用户喜欢,则显示 page_1,否则显示 page_2。

4

3 回答 3

5
<?php 
$user = $facebook->getUser(); 
if ($user) { 

try{ 
$user_profile = $facebook->api('/me');
 $likeID = $facebook->api(array( 'method' => 'fql.query',
 'query' => 'SELECT url FROM url_like WHERE user_id = "'.$user_profile['id'].'" AND url="myurl/"'; )); 
}
 catch(FacebookApiException $e) { }
 } 
if(count($likeID)>0) echo "User likes this page"; 
else echo "User doesn\'t like this page";

?>

可靠和/或官方消息来源:

  1. http://www.zuberi.me/2011/how-to-check-if-user-liked-the-application-or-page.html
  2. http://www.chilipepperdesign.com/2011/02/15/reveal-fan-gate-like-gate-facebook-iframe-tab-tutorial-with-php
  3. 如何使用 Facebook 的 API 检查用户是否喜欢我的 Facebook 页面或 URL
  4. Facebook如何检查用户是否喜欢页面并显示内容?
  5. Facebook 检查用户是否“喜欢”该页面
于 2012-05-11T11:29:52.717 回答
2

解决该问题的更好方法是:

// to generate user access token after the user is logged in
$USER_ACCESS_TOKEN = $facebook->getExtendedAccessToken();

$isFan = curl("https://api.facebook.com/method/pages.isFan?format=json&access_token=" . $USER_ACCESS_TOKEN . "&page_id=" . $FACEBOOK_PAGE_ID);

        function curl($url) {

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            $data = curl_exec($ch);
            curl_close($ch);
            return $data;
        }
于 2012-10-06T14:18:38.927 回答
1
require 'facebook.php';

$app_id = "your app id";
$app_secret = "your app secret";
$facebook = new Facebook(array(
    'appId' => $app_id,
    'secret' => $app_secret,
    'cookie' => true,
));

$signed_request = $facebook->getSignedRequest();


$like_status = $signed_request["app"]["liked"];


if ($like_status == 1){
echo 'User likes this page';
}
else{
echo 'User doesn\'t like this page';
}

也许你应该尝试这样的事情,查看Facebook 的 PHP SDK 参考页面以了解确切的方法。

于 2012-04-09T15:44:39.183 回答