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:
- Is my site visitor currently logged in to Facebook? [YES] [NO]
- 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.