3

I previously have an FBML application in Facebook and now change to an IFrame application in FB, using the graph API. (under the same name, same game account. Just switch from FBML to iFrame).

I had a list of people with Extended Permission accepted for email. Since I change to IFrame, I can get their email... by what the API is told.

However, here is the problem.

1) When it was in FBML, I don't have their email. Only with their email permission. (that's what I was bounded)

2) I can get the user's email when they login and visit my application

3) However, I cannot get the user's email when they don't visit my application. Because some of them may not come back but I want to tell them about the update.

4) I tried to run the application using the email address I register for the application (i.e. the developer account), but still, I cannot retrieve their emails.

It seems that the application can only get the current login user. I cannot get their email even I'm the admin.

Is there any way I can do that?

For example: If a user 12345678 and go to my application, i can run this can get his email:

 $fql    =   "select  email from user where uid=12345678";

Obviously, that user cannot run and get information for user 23456.

e.g. $fql    =   "select  email from user where uid=23456";   <--- Fail

So, here is the problem come. I have thousands of people who previously signed up and accept the extended permission, how can I get their emails now? I cannot run this...

$fql    =   "select  email from user where uid=1000001";
$fql    =   "select  email from user where uid=1000002";
$fql    =   "select  email from user where uid=1000003";  
// assum 1000001 ... 1000003 are those users. 

I tried to login facebook using my dev account and do that, but, still it won't work. Appreciate if anyone has the solution. thanks.

murvinlai
  • 48,919
  • 52
  • 129
  • 177
  • Have a look, i have briefed out the steps, to get user information using facebook connect and facebook php sdk http://stackoverflow.com/questions/2718722/how-i-can-get-user-email-and-name-with-facebook-connect-new-platform/10766525#10766525 – Rafee May 26 '12 at 13:13

3 Answers3

1

The idea is to get the user's email when he logs in, then store it in your own database for future reference.

Domenic
  • 110,262
  • 41
  • 219
  • 271
  • i know. but my problem is how to get all emails. – murvinlai Nov 01 '10 at 21:45
  • You cannot get the email of a user who has not authorized your application... is that what you mean by "all emails"? Or is your question, how do I get the email of a user when that user authorizes the application? – Domenic Nov 01 '10 at 21:55
  • No. please read my email carefully. I got the users authorized and they also accepted the extended permission BEFORE I switch it to IFrame app. so, now, I'm in iFrame app, how can I get back their email? – murvinlai Nov 01 '10 at 22:11
  • Ah I see, you edited your question to be clearer. But I don't really know how to solve your newly-clarified problem :(. If you never saved the information before, it seems unlikely you'll be able to retrieve it now, assuming you didn't save their auth tokens or anything else like that. The email permission essentially translates to "when this application uses my auth token to request an email, allow the application to have it." It doesn't mean "this application now has access to my entry in the central database of Facebook user emails." It's a good question though!! – Domenic Nov 02 '10 at 01:11
1
    You can get  user email address and details in Facebook (Facebook Connect or Graph API)
<?php

require '../src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => '344617158898614',
  'secret' => '6dc8ac871858b34798bc2488200e503d',
));

// See if there is a user from a cookie
$user = $facebook->getUser();

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
      echo "FacebookApiException";
    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
    $user = null;
  }
}

?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <body>
    <?php if ($user) { ?>
      Your user profile is
      <pre>
        <?php print htmlspecialchars(print_r($user_profile, true)) ?>
      </pre>
    <?php } else { ?>


      <div class="fb-login-button" data-scope="email,user_checkins">
        Login with Facebook
      </div>
    <?php } ?>
    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId: '<?php echo $facebook->getAppID() ?>',
          cookie: true,
          xfbml: true,
          oauth: true
        });
        FB.Event.subscribe('auth.login', function(response) {
          window.location.reload();
        });
        FB.Event.subscribe('auth.logout', function(response) {
          window.location.reload();
        });
      };
      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());
    </script>
  </body>
</html>
Nanhe Kumar
  • 15,498
  • 5
  • 79
  • 71
0

First, make sure that you include email in the scope of permissions like so:

https://www.facebook.com/dialog/oauth?client_id=595603433841467&redirect_uri=http://127.0.0.1:8000/faceb_login/&scope=email

Next retrieve the oauth token as documented elsewhere. Then, to actually retrieve a person’s email, you can make the following request:

https://graph.facebook.com/1162321772?fields=email&access_token=XXXXXXXXXXXXXXXXXXXXXX...

The documentation for the graph api is here:

https://developers.facebook.com/docs/graph-api/using-graph-api