如何检查用户的Facebook应用程序?

时间:2012-04-09 13:41:08

标签: php facebook facebook-graph-api facebook-like facebook-page

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

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

3 个答案:

答案 0 :(得分: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. How to check if a user likes my Facebook Page or URL using Facebook's API
  4. Facebook how to check if user has liked page and show content?
  5. Facebook Check if user "Liked" the page

答案 1 :(得分: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;
        }

答案 2 :(得分: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's PHP SDK reference page的确切方法。