title: How to get the email address of a Facebook user using the graph API?
body: <p>I have read through <a href="https://stackoverflow.com/questions/3611682/facebook-graph-api-how-to-get-users-email">this post</a> over and over, and yet it doesn't make sense to me.</p>
  
  <p>What I am trying to do is acquire a Facebook user's email address so that I can store it in a string and compare to see if it matches the emails of existing users in my MySQL database. I only need to to do this when the user first grants access rights to the app.</p>
  
  <p>In the "Authenticated Referrals" section of my app developer interface, I have set "User &amp; Friend Permissions" to include "email".</p>
  
  <p>Within the "canvas" area of my site, I have this code:</p>
  
  <pre><code>include('facebook/base_facebook.php');
  include('facebook/facebook.php');
  $facebook = new Facebook(array(
      'appId'  =&gt; "XXXXXXXXXXXXXXX",
      'secret' =&gt; "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  ));
  $user = $facebook-&gt;getUser();
  if ($user)
  {
      try {
          $user_profile = $facebook-&gt;api('/me');
      } catch (FacebookApiException $e) {
          $user = null;
      }
  }
  </code></pre>
  
  <p>If I var_dup() $user, I can see the user id (though not much else) which seems to be correct, so I believe I'm connecting to the right place on Facebook.</p>
  
  <p>But then there was <a href="https://stackoverflow.com/questions/3611682/facebook-graph-api-how-to-get-users-email#comment3792810_3611781">this suggested line of code</a>, which implies that it returns an email address, but when I echo it out to see what it looks like, it doesn't return an email address: </p>
  
  <pre><code>echo "&lt;br/&gt;" . $facebook-&gt;getLoginUrl(array('req_perms' =&gt; 'email'));
  </code></pre>
  
  <p>I kind of thought it wouldn't, as it doesn't look quite right to me, but on the other hand, I just have no idea what else to do with it or where to put it.</p>
  
  <p>And then I also came across <a href="https://stackoverflow.com/questions/4072819/how-to-get-the-user-email-address-in-facebook-facebook-connect-or-graph-api">this post</a>, which has code mixed in with the HTML in a way that baffles me even further.</p>
  
  <p>Assuming that my user has granted permission for my app to see their email, isn't there a simple way of getting at it? Something an inexperienced programmer like myself can grasp?</p>