Roman Müller
Roman Müller

Reputation: 43

How to detect if is the user the fan of my page

I have a little problem, I don't know how to create the script (with PHP SDK) which check if is the user a fan of my page.

I successfly get the permission for user_likes, but I cant post data to array and after check it.

When I dump this code: $user_likes = $facebook->api('/me/likes'); I'll got all data, but I cant post them to array.

Upvotes: 0

Views: 3121

Answers (3)

Coder
Coder

Reputation: 36

FB.api("me/likes/270801249647033", function(response) {
    if ( response.data.length == 1 ) { 
        // Has liked
    } else {
        // Not liked
}});

Source and download script

Upvotes: 1

DMCS
DMCS

Reputation: 31860

From: http://developers.facebook.com/docs/reference/rest/pages.isFan/ (yes, this is deprecated, but it includes the new Graph API way to do things at the top of it. :) )

You can now issue a HTTP GET request to /USER_ID/likes/PAGE_ID (aka /me/likes/PAGE_ID ) to check if a user is a page of a fan.

Upvotes: 0

Nitzan Tomer
Nitzan Tomer

Reputation: 164129

It's amazing what one can find on the internet these days if only he tries to Google his questions...

Here's the first result I got for "facebook is the user a fan":

http://www.masteringapi.com/tutorials/facebook-api-check-if-a-user-is-fan-of-a-facebook-page/20/

It discuss a few options, PHP and JavaScript, Graph API and REST API, just pick your favorite.

Upvotes: 2

Related Questions