Search code examples
facebookfacebook-graph-apifacebook-likefacebook-fql

How to trace if visitor already "liked" page via Facebook using JS only?


After checking 20+ answers I'm sure there is no way to trace (using JS only) if user already "liked / recommended" page few days ago or not - but anyway: how to trace if page on 3rd party site ("application") already liked by visitor few days ago?

I need JS code - without server-side languages like PHP - something like

FB.api(
  {
    method: 'link.getStats',
    url: 'example.com'
  },
  function(response) {
    if(response.liked) {
      alert('me likey!');
  }
);

Is there something like this? Thanks!


Solution

  • You can use the graph API to confirm if a user likes a page.

    You'll need the ID of the object to query though.

    FB.api('/me/likes/[page_id]',
      function(response) {
        if(response.data.length > 0) {
          alert('me likey!');
      }}
    );