Is there any way to determine if a Facebook user 'likes' a certain page with the API Facebook offers currently?
I have been trying to get this to work via the PHP graph API for a while now with this code.
$fbconfig['appid'] = '***';
$fbconfig['api'] = '***';
$fbconfig['secret'] = '***';
try {
include_once "facebook.php";
} catch(Exception $o) {
echo '<pre>';
print_r($o);
echo '</pre>';
}
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'cookie' => true,
));
$session = $facebook->getSession();
$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
d($e);
}
}
if($me) {
try {
$likes = $facebook->api('/me/likes');
} catch(Exception $o) {
d($o);
}
}
However, the session is always null, even though I am logged in.
Apparently, the above code is only good for Facebook Connect "Canvas" applications, I am calling this code from an FBML tab on a Facebook "Page" through an AJAX call to my server.
I'm not very familiar with all of the Facebook development terminology.
How can I get the current user's 'likes' in my situation?
Find a list of all the people who "like" your page on the left side of the page: Look for a number followed by "people like this." Click the "people like this" part, and you'll see a list of people who "like" your page appear in a pop-up window.
You can see a complete list of people who have liked your business page by logging into your Facebook Business Page on Facebook. Click on Settings in the upper right hand side of your page. button at the top-right corner, to the right of this Help Center article's title, to view this content.
Click the magnifying glass icon at the upper corner of your screen and enter the name of the Facebook user in the search bar. Choose the “About info” to be directed to the pages that they liked. In the likes section, you will see the pictures, videos and other content that the user liked. Click the “View all”.
It's at the top of your friend's profile, but below their cover photo. A menu will expand with more options. Click Likes on the menu. This opens your friend's Likes page, where you'll find all of the movies, TV shows, artists, books, restaurants, and other Pages they've liked on Facebook.
There's a way to do that without requesting permission and without using any kind of API.
If you have PHP:
<?php
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
$app_data = isset($data["app_data"]) ? $data["app_data"] : '';
$_REQUEST["fb_page_id"] = $data["page"]["id"];
$access_admin = $data["page"]["admin"] == 1;
$has_liked = $data["page"]["liked"] == 1;
?>
You can use $has_liked to wrap your fan-specific content
<?php if($has_liked) : ?>
fan-specifc
<?php else : ?>
for non-fans only
<?php endif; ?>
replaces
<fb:visible-to-connection>
fan-specific content
<fb:else>
for non-fans only
</fb:else>
</fb:visible-to-connection>
It's very useful and convenient, since asking for permission is a turn-off.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With