Facebook login scope email

When you use Facebook Login to authenticate a user, you can request specific permissions or scopes to access certain information about the user. One of the most common scopes is email.

The email scope allows your app to access the user's email address. When you request the email scope, Facebook will prompt the user to grant your app permission to access their email address.

Here's an example of how you can request the email scope in your Facebook Login implementation:

Client-side (JavaScript)

FB.login(function(response) {
  if (response.authResponse) {
    FB.api('/me', { fields: 'email' }, function(response) {
      console.log(response.email);
    });
  }
}, { scope: 'email' });

Server-side (PHP)

$fb = new Facebook(array(
  'appId' => 'YOUR_APP_ID',
  'secret' => 'YOUR_APP_SECRET',
));

$fb->setAccessToken($access_token);

$user = $fb->api('/me', array('fields' => 'email'));

echo $user['email'];

Server-side (Python)

import facebook

graph = facebook.GraphAPI(access_token=access_token)

user = graph.get_object('me', fields='email')

print(user['email'])

When you request the email scope, Facebook will prompt the user to grant your app permission to access their email address. If the user grants permission, Facebook will return the user's email address in the response.

Note that the email scope is considered a "basic" permission, which means that it is only granted to apps that have a legitimate reason to access the user's email address. Facebook has strict guidelines around the use of the email scope, and you should only request it if your app has a legitimate reason to access the user's email address.

Also, keep in mind that the email scope is only available for users who have granted your app permission to access their email address. If a user has not granted permission, Facebook will not return their email address, even if you request it.