0

I'm new to the Facebook development environment, and cannot figure out how to detect the Like status of my site's fan page.

I've reviewed How to check if a user likes my Facebook Page or URL using Facebook's API and https://developers.facebook.com/docs/reference/api/, among other resources, to no avail.

What I'm trying to detect is which of the following conditions is true using JavaScript:

  1. Is my site visitor currently logged in to Facebook? [YES] [NO]
  2. If the user is logged into Facebook, have they liked the brand page (Facebook fan page) [YES] [NO]

My logic would be something like this:

if ( [user is logged into facebook] ){
// check to see if user is a fan of the page
var query = FB.Data.query( 'select page_id from page_fan where uid=me() and page_id ='[PAGE_ID]');
query.wait( function(rows) ) {
    if(rows.length) {
        // User already likes the page
        echo('Thanks for liking the page!');
    }
    else {
        // User has not yet liked the page
        echo('Like us on Facebook!');
    }
});

}

else {
// User is not logged into Facebook
echo('Hello, world!');

}

I'm not clear about what to do from here. I've read through dozen of articles relating to this an similar issues, but most of them seem to be outdated, referencing the deprecated FBML and/or REST APIs.

FWIW, I see lots of references to needing an APPID, however, I do not have a Facebook app. I'm only trying to determine if the user on my website has liked our associated brand/fan page on Facebook.

Community
  • 1
  • 1
Andrew
  • 395
  • 6
  • 18

1 Answers1

1

FWIW, I see lots of references to needing an APPID, however, I do not have a Facebook app.

Then create one. What you want to do can not be done without an app.

I'm only trying to determine if the user on my website has liked our associated brand/fan page on Facebook.

If your app would be embedded into Facebook as a page tab app, then the way to go is to parse the signed_request parameter server-side.

If that’s not the case, or you want to stick strictly to client-side JavaScript – then you have to have the user connect to your app first, ask his permission to read his likes, and then grab the info from the Graph API.

CBroe
  • 91,630
  • 14
  • 92
  • 150