2

I have a web page which displays Facebook LIKE Box.. I need to check if a user liked my Facebook page or not and present contents to them accordingly.. doing Facebook authentication for this from my external web page is perfectly fine..

Ansar Muhammad
  • 1,218
  • 5
  • 23
  • 45

2 Answers2

8

You need to use the Graph API with and check the User's likes. Here is an example.

https://graph.facebook.com/{USER_ID}/likes/{PAGE_ID}

If the user likes the page in question, it will return JSON looking like this if the user likes the page.

{
  "data": [
    {
      "name": "bread&cup", 
      "category": "Restaurant/cafe", 
      "id": "157758372652", 
      "created_time": "2012-02-15T15:36:38+0000"
    }
  ], 
  "paging": {
    "next": "https://graph.facebook.com/me/likes/157758372652?format=json&limit=5000&offset=5000&__after_id=157758372652"
  }
}

And like this if the user doesn't like the page:

{
  "data": [
  ]
}

Here's the documentation on User likes: https://developers.facebook.com/docs/reference/api/user/#likes

derekaug
  • 2,055
  • 1
  • 17
  • 17
0

There is another way that doesn't require permissions in advance, but doesn't work perfectly on its own - ideally use it in conjunction with a log in system.

1) Subscribe to the Facebook.edge event (this means 'do something when like is clicked') 2) Create a cookie when user likes the page

Then, when a user returns, you can run the following code:

1) If user logged in, check FB API and check properly 2) If user not logged in, check cookie

This means the user who liked your site will get full access to whatever it is you're giving to fans only from that computer until they clear their cookies - at which point they will have to sign in to your site and provide like permissions.

Here's facebook edge event - Facebook edge.create

Here's create cookie stuff - How do I set/unset cookie with jQuery?

Dave

Community
  • 1
  • 1
Dave Hilditch
  • 5,008
  • 3
  • 25
  • 35