我创建了一个在Facebook上使用登录的应用程序,但我无法捕获用户的电子邮件地址,我知道我需要使用范围,但不知道如何。我怎样才能做到这一点? 这是我的代码:
window.fbAsyncInit = function() { FB.init({ appId : '<?= $this->getAppId(); ?>', // App ID channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true, // parse XFBML oauth : true }); FB.Event.subscribe('auth.authResponseChange', function(response) { // Here we specify what we do with the response anytime this event occurs. if (response.status === 'connected') { testAPI(); } else if (response.status === 'not_authorized') { FB.login() } else { FB.login() } }); } // Load the SDK asynchronously (function(d){ var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; ref.parentNode.insertBefore(js, ref); }(document)); // Here we run a very simple test of the Graph API after login is successful. // This testAPI() function is only called in those cases. function testAPI() { console.log('Welcome! Fetching your information.... '); FB.api('/me', function(response) { console.log('Good to see you, ' + response.name + '.'); console.log( response.email); }); }
答案 0 :(得分:1)
您将所需的任何其他权限作为参数(以逗号分隔多个权限)传递给FB.login()
。在您的情况下,您需要email
:
FB.login(function(response) {
// handle the response
}, {scope: 'email'});
FB JS SDK Documentation 非常清楚解释了这一点。请花点时间阅读。
答案 1 :(得分:0)
我解决了这个问题,当使用FB.Event.subscribe时,我们需要将权限放在html而不是FB.login()函数中,使用这种方式:
fb:login-button show-faces =“true”perms =“email,user_birthday”width =“200”max-rows =“1
由于