How to check if current facebook user like a page using PHP SDK?

前端 未结 2 1383
我在风中等你
我在风中等你 2021-01-14 06:35

How can i check if the current facebook user like a facebook page?

I have this code,

require_once(\"/path/to/sdk/facebook.php\");


    // Create our         


        
相关标签:
2条回答
  • 2021-01-14 06:57

    You can use FQL

    $isFan = $facebook->api(array(
      "method" => "fql.query",
      "query"  => "SELECT uid FROM page_fan WHERE page_id = '<YOUR PAGE ID>' AND uid = '<UID>"
    ));
    
    0 讨论(0)
  • 2021-01-14 07:17

    I don't know if you need to do this only using FQL, but there is another easier way:

    require_once("/path/to/sdk/facebook.php");
    
    // Create our Application instance (replace this with your appId and secret).
    $facebook = new Facebook(array(
      'appId' => 'APP_ID',
      'secret' => 'APP_SECRET',
    ));
    
    $signed_request = $facebook->getSignedRequest();
    
    $like = $signed_request['page']['liked'];
    

    $like will be empty or 1.

    I like to check variables first, like this:

    if(is_array($signed_request) && isset($signed_request['page']) {
      if($signed_request['page']['liked']) {
        // do whatever you want to do if the user likes the page
      } else {
        // do whatever you want to do if the user don't like the page yet
      }
    }
    
    0 讨论(0)
提交回复
热议问题