Fb uid js mail

You're looking for a JavaScript code to fetch a Facebook user's ID (UID) and email address using the Facebook SDK.

Here's an example code snippet that demonstrates how to do this:

// Import the Facebook SDK
window.fbAsyncInit = function() {
  FB.init({
    appId: 'YOUR_APP_ID',
    cookie: true,
    xfbml: true,
    version: 'v13.0'
  });
};

// Load the Facebook SDK
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = 'https://connect.facebook.net/en_US/sdk.js';
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

// Get the Facebook user's ID and email address
FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    var uid = response.authResponse.userID;
    var email = response.authResponse.email;
    console.log('User ID:', uid);
    console.log('Email:', email);
  } else {
    console.log('User is not connected to Facebook');
  }
});

Make sure to replace YOUR_APP_ID with your actual Facebook app ID.

Here's how the code works:

  1. We import the Facebook SDK using the window.fbAsyncInit function.
  2. We load the Facebook SDK using a script tag.
  3. We use the FB.getLoginStatus function to check the user's login status. If the user is connected to Facebook, we get their user ID and email address from the authResponse object.
  4. We log the user ID and email address to the console.

Note that this code requires the user to have granted your app permission to access their email address. You can do this by adding the email permission to your app's settings in the Facebook Developer Portal.

Also, keep in mind that this code is just an example and you should adapt it to your specific use case. Additionally, you should handle errors and edge cases properly in your production code.