2015-10-18 103 views
4

我想用facebook api返回用戶的電子郵件地址。幾天前它工作正常,但今天停止工作,不知道爲什麼。facebook api沒有返回電子郵件

所以首先我得到的訪問令牌:

FB.login(response => { 
    if (response.authResponse) { 
     resolve(response.authResponse.accessToken); 
    } else { 
     reject({ 
     error: 'User cancelled login or did not fully authorize.' 
     }); 
    } 
    }, { 
    scope: 'public_profile,email' 
    }); 

然後我會試圖獲取用戶數據

FB.api('/me', {fields: 'first_name,last_name,email'}, function(response) { 
    console.log(response); 
}); 

,但我只得到First_Name和Last_Name數據。沒有電子郵件。

另外,當我要求權限,它給了我電子郵件,如我所說,電子郵件不返回。

FB.api('/me/permissions', function(response) { 
    console.log(response); 
}); 

有沒有人知道可能是什麼問題?

順便說一句:我正在使用API​​ v2.4。

+0

嘗試在圖形API瀏覽器的請求首先,使用您的應用ID和相同的訪問令牌的JS使用(應包含在'response'對象,因此其記錄到控制檯,將其複製並從那裏粘貼。 )另外,請確保用戶在其帳戶中設置了有效的電子郵件地址,並確認其已被驗證。 – CBroe

+0

這是發生在你的所有用戶,還是僅僅一個或幾個?像CBroe提到的一樣;可能是有人從他們的個人資料中刪除了他們的電子郵件。 – Roemer

回答

15
FB.api('/me?fields=email,name', function(response) { /* stuff here */ }); 

嘗試將您的返回字段添加到您的請求。

+1

這不是它,推薦的方式將是一個額外的參數:https://developers.facebook.com/docs/javascript/reference/FB.api - 也,他得到其他領域,只有電子郵件丟失。 – luschn

+0

是的,絕對是電子郵件缺少任何解決方案請 –

+0

此解決方案爲我工作,傳遞領域作爲參數不一致。 –

1

可能的原因是用戶未驗證電子郵件。嘗試與另一個用戶驗證電子郵件,以確保這不是問題。

又見this answer

2

我知道這不過是老問題,如果有人仍然seraching答案,然後下面的解決方法爲我工作。

您需要在範圍scope="public_profile,email"中添加電子郵件。

<fb:login-button scope="public_profile,email" autologoutlink="false" onlogin="OnRequestPermission();"></fb:login-button> 
-1

我使它工作使用一個承諾並加入{範圍:「電子郵件」}的初始請求,那麼,包括在fb.api字段「電子郵件」。

fb.login({scope:'email'}).then(function (resp) { 
    if (resp.status === 'connected') { 
     fb.api('/me', 'get', {fields:'id,email,first_name,gender,...'}).then(function (FbUserData) { 
      console.log(FbUserData); 
     }); 
    } 
}); 
相關問題