Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Determine if Facebook User 'Likes' a Certain Page

Is there any way to determine if a Facebook user 'likes' a certain page with the API Facebook offers currently?

UPDATE

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?

like image 342
bimbom22 Avatar asked Jan 16 '11 03:01

bimbom22


People also ask

Can you tell when someone likes a page on Facebook?

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.

Can you see who likes a business page on Facebook?

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.

Can you track what someone likes on Facebook?

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”.

How can I see someone else's likes on Facebook?

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.


1 Answers

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.

like image 146
Racoonsteak Avatar answered Oct 03 '22 14:10

Racoonsteak