Fed*_*llo 4 facebook facebook-javascript-sdk facebook-login
我有一个Facebook登录实施的网站.我的应用程序拥有用户电子邮件的权限.即使用户使用Facebook登录我的应用程序,我也只能检索他/她的名字或基本信息.不是电子邮件.所以,这是我从Facebook开发者网站上复制的代码:
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxxxxx', // App ID
channelUrl : '//domain.org/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
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
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));
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.email + '.');
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
lus*_*chn 22
您现在必须指定要获取的字段,称为"声明字段":
FB.api('/me', {fields: 'name,email'}, function(response) {
console.log('Good to see you, ' + response.email + '.');
});
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅更改日志:https://developers.facebook.com/docs/apps/changelog#v2_4
归档时间: |
|
查看次数: |
16165 次 |
最近记录: |