我正在尝试开发一个应用程序,它将登录Facebook用户的电子邮件地址导入到我的网站上 - 像yahoo联系人导入程序和其他联系人导入程序。从登录Facebook用户导入电子邮件地址?
- 用户 'X' 已经登录的Facebook。
- 应用程序有一组朋友的UID(用户'X'的可能朋友)。
我想这些的UID的电子邮件地址,但只有UID,生日,名字,名字,姓氏出现在查询结果和电子邮件地址显示为NULL。不过,我说关系到朋友所有扩展权限,如:
(perms:'publish_stream,read_stream,offline_access,manage_pages,friends_activities,friends_about_me,user_hometown,user_birthday,user_about_me,user_hometown,user_photos,email,manage_friendlists,read_friendlists')
注:我浏览了Facebook的开发人员API,但没有找到任何解决方案。
我的代码:
<body>
<h1>Login to FaceBook using My Web Application</h1>
<div>
<button id="login">Log In</button>
<button id="logout">Log Out</button>
<button id="disconnect">Disconnect</button>
</div>
<div id="user-info" style="display: none;"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
// initialize the library with the API key
FB.init({ apiKey: 'c2e2e62acc6a292c20c63404bcfecb23' });
// fetch the status on load
FB.getLoginStatus(handleSessionResponse);
$('#login').bind('click', function() {
FB.login(handleSessionResponse,{perms:'publish_stream,read_stream,offline_access,manage_pages,friends_activities,friends_about_me,user_hometown,user_birthday,user_about_me,user_hometown,user_photos,email,manage_friendlists,read_friendlists'});
});
$('#logout').bind('click', function() {
FB.logout(handleSessionResponse);
});
$('#disconnect').bind('click', function() {
FB.api({ method: 'Auth.revokeAuthorization' }, function(response) {
clearDisplay();
});
});
// no user, clear display
function clearDisplay() {
$('#user-info').hide('fast');
}
// handle a session response from any of the auth related calls
function handleSessionResponse(response) {
// if we dont have a session, just hide the user info
if (!response.session) {
clearDisplay();
return;
}
FB.api(
{
method: 'fql.query',
query: 'SELECT pic,hometown_location,name,username, uid, email, sex, birthday FROM user WHERE uid=' + FB.getSession().uid
},
function(response) {
var user = response[0];
$('#user-info').html("<img src="+user.pic+"/>"+'<br/>ID: '+user.uid +'<br/>User Name: '+ user.name +'<br/>Email: '+ user.email +'<br/>Birth Day: '+ user.birthday +'<br/>Gender: ' + user.sex+'<br/>Home Town: ' +user.hometown_location['state']).show('fast');
}
);
// if we have a session, query for the user's profile picture and name
FB.api(
{
method: 'friends.get'
},
function(response)
{
$(response).each(function() {
var userid = this;
FB.api(
{
method: 'fql.query',
query: 'SELECT uid,name,email,birthday FROM user WHERE uid=' + userid
},function(response)
{
var user = response[0]
$('#user-info').append('<br/>ID: '+user.uid+ ', Name: '+user.name+' ,Email: '+user.email);
});
});
}
);
}
</script>
</body>
对不起,我需要在登录后从我的friendsList提取电子邮件,我不不会有任何的电子邮件联系,检查寄存器 – 2011-01-20 11:35:39
的Facebook不允许提取电子邮件。你只能得到电子邮件的散列。 – 2011-01-20 14:15:33