无法通过Facebook API获取用户电子邮件(Not able to fetch user email via facebook api)

编程入门 行业动态 更新时间:2024-10-11 19:25:40
无法通过Facebook API获取用户电子邮件(Not able to fetch user email via facebook api)

我在下面使用:

window.fbAsyncInit = function() { FB.init({ appId : 'my-app-id', xfbml : true, version : 'v2.7' }); }; (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 = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));

并试图获取电子邮件信息如下:

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

输出是:Nitesh Kumar ---未定义

如何获取用户的电子邮件?

I am using below:

window.fbAsyncInit = function() { FB.init({ appId : 'my-app-id', xfbml : true, version : 'v2.7' }); }; (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 = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));

and trying to get email info as below:

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

The output is : Nitesh Kumar --- undefined

How to get email of user?

最满意答案

您需要在登录过程中询问电子邮件权限:

FB.login(function(response) { if (response.authResponse) { //user just authorized your app } }, {scope: 'email'});

顺便说一句,这是正确的(包括最先进的ES6箭头功能):

FB.api('/me', {fields: 'name,email'}, (response) => { console.log(response.name + ' --- ' + response.email); });

更多信息: http : //www.devils-heaven.com/facebook-javascript-sdk-login/

You need to ask for the email permission in the login process:

FB.login(function(response) { if (response.authResponse) { //user just authorized your app } }, {scope: 'email'});

Btw, this would be correct (including state oft the art ES6 arrow functions too):

FB.api('/me', {fields: 'name,email'}, (response) => { console.log(response.name + ' --- ' + response.email); });

More information: http://www.devils-heaven.com/facebook-javascript-sdk-login/

更多推荐

本文发布于:2023-07-29 03:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1311988.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电子邮件   用户   Facebook   API   fetch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!