How to check if a user likes my Facebook Page or URL using Facebook's API

后端 未结 5 1114
囚心锁ツ
囚心锁ツ 2020-11-22 02:37

I think I\'m going crazy. I can\'t get it to work.
I simply want to check if a user has liked my page with javascript in an iFrame app.

FB.a         


        
5条回答
  •  一整个雨季
    2020-11-22 03:22

    You can use (PHP)

    $isFan = file_get_contents("https://api.facebook.com/method/pages.isFan?format=json&access_token=" . USER_TOKEN . "&page_id=" . FB_FANPAGE_ID);
    

    That will return one of three:

    • string true string false json
    • formatted response of error if token
    • or page_id are not valid

    I guess the only not-using-token way to achieve this is with the signed_request Jason Siffring just posted. My helper using PHP SDK:

    function isFan(){
        global $facebook;
        $request = $facebook->getSignedRequest();
        return $request['page']['liked'];
    }
    

提交回复
热议问题