title: Facebook JavaScript SDK and Like Status
body: <p>I'm new to the Facebook development environment, and cannot figure out how to detect the Like status of my site's fan page.</p>
  
  <p>I've reviewed <a href="https://stackoverflow.com/questions/5093398/check-if-user-liked-page">How to check if a user likes my Facebook Page or URL using Facebook&#39;s API</a> and <a href="https://developers.facebook.com/docs/reference/api/" rel="nofollow noreferrer">https://developers.facebook.com/docs/reference/api/</a>, among other resources, to no avail.</p>
  
  <p>What I'm trying to detect is which of the following conditions is true using JavaScript:</p>
  
  <ol>
  <li>Is my site visitor currently logged in to Facebook? [YES] [NO]</li>
  <li>If the user is logged into Facebook, have they liked the brand page (Facebook fan page) [YES] [NO]</li>
  </ol>
  
  <p>My logic would be something like this:</p>
  
  <pre><code>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!');
  
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>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. </p>