我创建了一个在 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); }); }