Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  143] [ 2]  / answers: 1 / hits: 157033  / 14 Years ago, wed, february 23, 2011, 12:00:00

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.api({
method: pages.isFan,
page_id: my_page_id,
}, function(response) {
console.log(response);
if(response){
alert('You Likey');
} else {
alert('You not Likey :(');
}
}
);


This returns: False

But I'm a fan of my page so shouldn't it return true?!


More From » facebook

 Answers
26

I tore my hair out over this one too. Your code only works if the user has granted an extended permission for that which is not ideal.



Here's another approach.



In a nutshell, if you turn on the OAuth 2.0 for Canvas advanced option, Facebook will send a $_REQUEST['signed_request'] along with every page requested within your tab app. If you parse that signed_request you can get some info about the user including if they've liked the page or not.



function parsePageSignedRequest() {
if (isset($_REQUEST['signed_request'])) {
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}
if($signed_request = parsePageSignedRequest()) {
if($signed_request->page->liked) {
echo This content is for Fans only!;
} else {
echo Please click on the Like button to view this tab!;
}
}

[#93611] Tuesday, February 22, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tylerdamiena

Total Points: 139
Total Questions: 90
Total Answers: 118

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
tylerdamiena questions
;