2011-01-19 80 views
1

我正在嘗試開發一個應用程序,它將登錄Facebook用戶的電子郵件地址導入到我的網站上 - 像yahoo聯繫人導入程序和其他聯繫人導入程序。從登錄Facebook用戶導入電子郵件地址?

  1. 用戶 'X' 已經登錄的Facebook。
  2. 應用程序有一組朋友的UID(用戶'X'的可能朋友)。
  3. 我想這些的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> 

回答

1

您可以通過FQL得到用戶的朋友的電子郵件哈希值(表 「用戶」 的領域 「email_hashes」)。

另一種方式來綁定用戶到Facebook用戶 - 使用方法「搜索」(它可以通過電子郵件搜索Facebook的用戶)。當我遇到同樣的問題時,我使用它。

例如,此API調用:

/[email protected]&type=user 

回報:

{ 
    "data": [ 
     { 
     "name": "Pavel Surmenok", 
     "id": "100001653100014" 
     } 
    ] 
} 

可以遍歷在您的電子郵件和搜索他們是否登記在Facebook上。

+0

對不起,我需要在登錄後從我的friendsList提取電子郵件,我不不會有任何的電子郵件聯繫,檢查寄存器 – 2011-01-20 11:35:39

+0

的Facebook不允許提取電子郵件。你只能得到電子郵件的散列。 – 2011-01-20 14:15:33

0

添加電子郵件到perms.You需要閱讀用戶的電子郵件地址擴展權限。即

perms:'email,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) 
相關問題