最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Using facebook API javascript getting email - Stack Overflow

programmeradmin2浏览0评论

I have this method and I want to get the email of a person and Send email=undefined.

First Try:

     function testAPI() {
    FB.login(function(response) {
     if (response.authResponse) {
       console.log('Welcome!  Fetching your information.... ');
       FB.api('/me', function(response) {
         console.log('Good to see you, ' + response.email + '.');
         alert('Good to see you, ' + response.email + '.');
       });
     } else {
       console.log('User cancelled login or did not fully authorize.');
     }
   }, {scope:'email'});

I was searching and i found that I have to use {scope:image} and if i put it, dont show me the alert

I have this method and I want to get the email of a person and Send email=undefined.

First Try:

     function testAPI() {
    FB.login(function(response) {
     if (response.authResponse) {
       console.log('Welcome!  Fetching your information.... ');
       FB.api('/me', function(response) {
         console.log('Good to see you, ' + response.email + '.');
         alert('Good to see you, ' + response.email + '.');
       });
     } else {
       console.log('User cancelled login or did not fully authorize.');
     }
   }, {scope:'email'});

I was searching and i found that I have to use {scope:image} and if i put it, dont show me the alert

Share Improve this question edited Jul 10, 2015 at 1:27 Steven Montero Cordero asked Jul 10, 2015 at 0:47 Steven Montero CorderoSteven Montero Cordero 611 gold badge2 silver badges8 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 24

Replacing this

FB.api('/me', function(response) {
  // ...

with this

FB.api('/me?fields=id,name,email,permissions', function(response) {
  console.log(response.name);
  console.log(response.email);
  // ...

I can get the user's email.

Your syntax is wrong, that's the correct one:

function testAPI() {
    FB.login(
        function(response) {
            if (response.authResponse) {
               console.log('Welcome!  Fetching your information.... ');
               FB.api('/me', function(response) {
                   console.log('Good to see you, ' + response.email + '.');
                   alert('Good to see you, ' + response.email + '.');
               });
            } else {
                console.log('User cancelled login or did not fully authorize.');
            }
        },
        {scope:'email'}
        );
}

where the {scope:'email'} is inside the ) as second argument of the FB.login

Or use

FB.init('/me', {"fields":"id,name,email,first_name,last_name"}, function(response){
console.log(response.email);
});
发布评论

评论列表(0)

  1. 暂无评论