如何通过 Facebook API 获取生日? [英] How to get birthday via Facebook API?

查看:23
本文介绍了如何通过 Facebook API 获取生日?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置 Facebook 登录,并且成功获取了诸如 first_nameemail 等内容.但是,我似乎不知道如何获得生日.如果我调用 birthday 如下,则没有任何返回.

I am setting up a Facebook login, and am successfully getting things like first_name, email, etc. However, I cannot seem to figure out how to get birthday. If I call for birthday as below, nothing returns.

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

如果我按如下方式调用 user_birthday,我会收到此错误:"error":{"message":"(#100) 尝试访问不存在的字段 (user_birthday)

If I call user_birthday as below, I get this error: "error":{"message":"(#100) Tried accessing nonexisting field (user_birthday)

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

我该怎么做?

推荐答案

由于您没有发布登录代码,也没有提及权限,我想您忘记了一件重要的事情:使用 user_birthday 许可.

Since you did not post your login code and you did not mention permissions, i assume you forgot one important thing: Authorizing with the user_birthday permission.

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

user_birthday 是权限,birthday 是字段的名称.如果它仍然不起作用,那么很可能没有设置生日.不确定是否需要.

user_birthday is the permission, birthday is the name of the field. If it still doesn´t work, then there is most likely no birthday set. Not sure if it is required.

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

这篇关于如何通过 Facebook API 获取生日?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆