回答

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
+0

我已經完成了它... – Aamir 2012-05-11 14:36:08

+0

<?php $ user = $ facebook-> getUser(); ($ user){ 嘗試{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 =「http:// myurl /」')); } 趕上(FacebookApiException $ E) { } } 如果(計數($ likeID)> 0) 回聲 「用戶喜歡當前頁」; else echo「用戶不喜歡這個頁面」; ?> – Aamir 2012-06-06 13:46:19

+1

你也可以更新我的答案。如果你覺得對其他用戶應該會更好。然後你也可以接受答案,如果這對你有幫助。 – 2012-06-06 13:57:25

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的確切方法。

+0

'的getUser(); ($ user){ \t嘗試{ \t $ user_profile = $ facebook-> api('/ me'); ('method'=>'fql.query', 'query'=>'SELECT url FROM url_like WHERE user_id =''。$ user_profile ['id']。' 「AND url =」http:// myurl /「' )); \t}趕上(FacebookApiException $ E){ \t} } 如果(計數($ likeID)> 0) 回聲 「用戶喜歡當前頁」; else echo「用戶不喜歡這個頁面」; ?>' 通過以上方法 – Aamir 2012-04-10 07:12:51

+0

嗨,弗蘭克,我不知道php。你能轉換它的JavaScript或asp.net爲我? – 2012-11-20 09:34:50

2

對這一問題的更好的方法可以是:<?PHP的 $用戶= $ facebook->

// 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; 
     } 
相關問題