Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
350 views
in Technique[技术] by (71.8m points)

javascript - Facebook Graph API won't return email address

Edit: Not Duplicate, because:

  • I have the permission
  • Debugged the token
  • Code works with test user

Please don't mark as duplicate without reading.

I'm trying to get the user e-mail address, but i don't get it. On graph api explorer, when i hit send, email field becomes grayed and says that:

field is empty or disallowed by access token

But when I debug the token it has email permission granted

My profile has an e-mail address.

Update: I tried https://developers.facebook.com/tools/console/ . My profile returns nothing, even on another computer. But the same code returns the email, name and uid of another account.

Code:

    <fb:login-button scope="email">
  Grant Permissions to make more examples work
</fb:login-button>

<button onclick="doPost()">Post to Stream</button>

<script>
function userData() {
  FB.api('/me?fields=name,email', Log.info.bind('/me callback'));
};

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    userData();
  }
});
</script>

It is possible to lockdown you e-mail so no one can has it? Even when i grant permission?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Marcus' answer leads me to the real problem I was facing.

Debugging with the Facebook Explorer tool I was able to figure out that I should set the email scope at the FB.api() method after a successful login.

FB.login(function(response) {
    if (response.status === 'connected'){
        FB.api('/me?fields=id,email,name', function(data) {
        console.log( data.email ) // it will not be null ;)
    })
}, {scope: 'email'});

It is not quite clear at the Quickstart guide and I hope it helps someone else, too.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...