1

I am having a confusing issue, I have a fanpage app/tab , and I want to know if the user liked it...usually this used to work , this is the code and i'm puzzled, if anyone can guide me on this please:

  $user = $facebook->getUser();

        $signedRequest = $facebook->getSignedRequest();

        if (!$user) {
            echo "Please <a target='_blank' href='".$login_url."'>click here</a> to login to the game first!";
            //echo "<a target='_blank' href='$login_url'><IMG SRC='images/likeus.jpg' border=0 width='100%' /></a>";
            die();
        }

 try {
            $likes = $facebook->api("/me/likes/316624641780313");
        }
        catch (FacebookApiException $e) {
            echo 'Please <a target="_blank" href="' . $login_url . '">click here</a> to login to the game.';

            error_log($e->getType());
            error_log($e->getMessage());

        }
roy naufal
  • 379
  • 1
  • 8
  • 19
  • What is happening / being returned? https://developers.facebook.com/docs/graph-api/reference/v2.0/user/likes#readmodifiers – Fosco Jun 02 '14 at 07:58
  • If it is a page tab app just look in the signed request. It will have a like property that tells you if the user liked the page – WizKid Jun 02 '14 at 08:15
  • that's exactly the issue WizKid, the signed request doesnt return anything related to the page :/ Fosco, it returns a blank array – roy naufal Jun 02 '14 at 14:47

2 Answers2

0

As you are using a Page Tab App, I'd suggest you use the data contained in the signed_request you receive from Facebook.

Have a look at my answer here:

perl Facebook::Graph API check if user likes page

Community
  • 1
  • 1
Tobi
  • 31,405
  • 8
  • 58
  • 90
  • this is what I usually do, but in this case the signed request is not containing any .page info, that entry never exists – roy naufal Jun 02 '14 at 14:48
  • You receive the signed_request only upon the first call from FB when the user clicks on the Page Tab icon. Please add a sample output to your question. – Tobi Jun 02 '14 at 15:21
  • 1 thing I did was moving the PHP code to below the JS code (which has the FB sdk), it suddenly worked (But am not sure if that was the cause, there was half a day difference , I was getting a sample output to reply here, and to my surprise it was working), any idea? – roy naufal Jun 02 '14 at 20:55
  • The only guess I have is that you didn't capture the first call from Facebook with your PHP script. Maybe there were some redirects? – Tobi Jun 03 '14 at 06:46
  • hmm, yes, could be, thanks alot for your time...what kind of redirects could work or not work (or how do I adjust to make them work)? I can save data in session but is that a good idea? if you can give a brief overview of the best approach you use, would be great! thanks again – roy naufal Jun 03 '14 at 15:16
0

If you are point to Facebook Graph Api 2.0 then you need to ask for user_likes permission. Please test here with API 2.0 and 1.0 and you will see the difference.

mpatel
  • 1