2016-01-21 84 views
4

我正在設置Facebook登錄,並且成功獲取像first_name,email等等的東西。但是,我似乎無法弄清楚如何獲得生日。如果我要求如下所示的birthday,則不返回任何結果。如何通過Facebook API獲得生日?

FB.api('/me', {fields: 'birthday'}, function(response) { 
    console.log(JSON.stringify(response)); 
}) 

如果我下面叫user_birthday,我得到這個錯誤:"error":{"message":"(#100) Tried accessing nonexisting field (user_birthday)

FB.api('/me', {fields: 'user_birthday'}, function(response) { 
    console.log(JSON.stringify(response)); 
}) 

我該怎麼辦呢?

+0

您確定每個用戶都輸入了生日嗎? –

+0

'birthday_date'有效嗎? – user5325596

回答

12

既然您沒有發佈您的登錄代碼,並且您沒有提及權限,我假設您忘記了一件重要的事情:授權user_birthday權限。

FB.login(function(response) { 
    if (response.authResponse) { 
     //user authorized the app 
    } 
}, {scope: 'user_birthday', return_scopes: true}); 

user_birthday是許可,birthday是字段的名稱。如果它仍然沒有工作,那麼很可能沒有生日套裝。不知道是否需要。

例如:http://www.devils-heaven.com/facebook-javascript-sdk-login/

相關問題