-1

Possible Duplicate:
How to check if a user likes my Facebook Page or URL using Facebook's API

how to check if user like a specific Facebook page or not from my website (using PHP or Javascript)

Fb App ID = 123456

Fb App Secret = `0123456789

Fbpage = http://www.facebook.com/mypage

my website = http://www.example.com

ex:

if user like Fbpage then

say "u are a fan"

else

say "u are not a fan"

Community
  • 1
  • 1
Mr Bean
  • 11
  • 1
  • 1

2 Answers2

2

From the Graph API likes documentation:

Belongs

You can check if a User likes a specific page by issuing an HTTP GET to /PROFILE_ID/likes/PAGE_ID. This will return, in the data array, an object with the following fields if the user is connected to the page.

You'll need a valid access token with the user_likes permission.

In Javascript, this might look like:

var page_id = 123456; // whatever

FB.init({
    // ...
});

FB.login(function(response)
{
    if (response.authResponse)
    {
         FB.api('/me/likes/' + page_id, function(api_response)
         {
             // if empty, they don't like. if not empty, they do
            console.debug(api_response); 
         });
    }
    
}, {'scope': 'user_likes'});
Community
  • 1
  • 1
Jimmy Sawczuk
  • 13,488
  • 7
  • 46
  • 60
0

You need to use the likes end point (http://graph.facebook.com) this is a json representation of a user's likes , interests etc. Just parse the list for your page id.

Steve
  • 21,163
  • 21
  • 69
  • 92