How to get user email address on Facebook (Facebook Connect or Graph API)?

I previously had the FBML application on Facebook and am now changing the IFrame application in FB using the graphical API. (under the same name, with the same game account. Just switch from FBML to iFrame).

I had a list of people with the extended resolution accepted for email. Since I am switching to IFrame, I can get their email ... by what the API said.

However, that is the problem.

1) When it was in FBML, I do not have email. By email only. (that I was limited)

2) I can get the user's email address when logging in and visit my application

3) However, I canโ€™t get the userโ€™s email when they donโ€™t visit my application. Because some of them may not return, but I want to tell them about the update.

4) I tried to launch the application using the email address that I registered for the application (i.e. the developer account), but still I can not receive their emails.

It seems that the application can only get the current login user. I can not get their email, even I am an administrator.

Can I do this?

For example: If the user is 12345678 and logs into my application, I can start, this can get his email address:

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

Obviously, the user cannot start and receive information for user 23456.

 eg $fql = "select email from user where uid=23456"; <--- Fail 

So here is the problem. I have thousands of people who have previously signed up and accepted extended permission, how can I get their email now? I can't 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 logging into facebook using my dev account and doing this, but it still won't work. Appreciate if anyone has a solution. thanks.

+3
source share
3 answers

The idea is to get the userโ€™s email when he logs in and then saves it in his own database for future use.

+1
source
  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 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> 
+1
source

First, make sure you include email in the permissions area:

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

Then extract the oauth token as described elsewhere. Then, to receive an email with people, you can make the following request:

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

The documentation for the api chart is here:

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

0
source

Source: https://habr.com/ru/post/1402202/


All Articles