Facebook api does not return email

I am trying to return the email address of a user using facebook api. A few days ago, it worked fine, but today it stopped working, and I don’t know why.

So first I get the access token:

FB.login(response => {
    if (response.authResponse) {
      resolve(response.authResponse.accessToken);
    } else {
      reject({
        error: 'User cancelled login or did not fully authorize.'
      });
    }
  }, {
    scope: 'public_profile,email'
  });

then I'm trying to get user data

FB.api('/me', {fields: 'first_name,last_name,email'}, function(response) {
  console.log(response);
});

but I only get data for first_name and last_name. No email.

Also, when I ask for permission, he gives me the email as provided, but, as I said, the letter is not returned.

FB.api('/me/permissions', function(response) {
  console.log(response);
});

Does anyone know what the problem is?

BTW: I am using API v2.4.

+4
source share
5 answers
FB.api('/me?fields=email,name', function(response) { /* stuff here */ });

Try adding return fields to your request.

+16

, , , - , .

scope="public_profile,email".

<fb:login-button  scope="public_profile,email" autologoutlink="false" onlogin="OnRequestPermission();"></fb:login-button>
+3

, . , , .

.

+1

, , FacebookLoginASPnetWebForms Asp.Net(https://github.com/nickpinheiro/FacebookLoginASPnetWebForms).

, N Nem (!).

Default.aspx.cs

In HyperLink1.NaviagteUrl add the query string parameter: & scope = public_profile, email

HyperLink1.NavigateUrl = "https://www.facebook.com/v2.4/dialog/oauth/?client_id=" + ConfigurationManager.AppSettings["FacebookAppId"] + "&redirect_uri=http://" + Request.ServerVariables["SERVER_NAME"] + ":" + Request.ServerVariables["SERVER_PORT"] + "/account/user.aspx&response_type=code&state=1&scope=public_profile,email";

I also had to fix some errors in order to parse the access token correctly.

This time an email address is available! Hope this helps?

0
source

I did this using the promise and adding {scope: 'email'} to the original request, including the “email” in the fb.api fields.

fb.login({scope:'email'}).then(function (resp) {
    if (resp.status === 'connected') {
       fb.api('/me', 'get', {fields:'id,email,first_name,gender,...'}).then(function (FbUserData) {
          console.log(FbUserData);
       });
    }
});
-1
source

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


All Articles