无法通过Facebook获取用户的生日 [英] Unable to get users' birthday via Facebook

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

问题描述

我一直在尝试通过Facebook Connect获取Facebook用户的生日,但我没有做到这一点.相同的代码以前可以工作,但仍然可以在较早创建的其他站点(旧站点)上工作,但似乎不再起作用.这是代码:

I have been trying to get a Facebook user's birthday through Facebook Connect but I have not managed to do so. The same code worked previously and still works on other sites made earlier (old ones) but does not seem to work again. Here is the code:

require_once ('./connect/facebook.php');

$facebook = new Facebook("myapi", "mysecret");
$fbuser = $facebook->get_loggedin_user();

if ($fbuser)
{
    $_SESSION['custid'] = $fbuser;

    $fb_look_fields = array(
                            'name', 
                            'first_name', 
                            'last_name', 
                            'name', 
                            'timezone', 
                            'name', 
                            'sex', 
                            'birthday',
                            'birthday_date',
                            'current_location', 
                            'proxied_email',
                            'affiliations'
                            );

    try
    {
        $user_data = $facebook->api_client->users_getInfo($fbuser, $fb_look_fields);
    }
    catch (Exception $e)
    {
         echo $e->getMessage();
    }

    # for birth date
    $fb_birthday = $user_data[0]['birthday'];

    if (!$fb_birthday)
    {
        $fql_result_xml = $facebook->api_client->fql_query("SELECT birthday FROM standard_user_info WHERE uid = " . $fbuser);
        $fb_birthday = $fql_result_xml['birthday'];
    }

    echo $fb_birthday;

即使我将生日设置为所有人可见,生日也总是空的.

The birthday is always empty even though I have set it to visible to all.

  • 我正在使用新的Facebook PHP客户端
  • 我什至尝试从标准表中获取信息,但没有任何运气

Facebook是否再次​​更改了其API/政策?还是我在代码中丢失/未正确执行什么操作?

Has Facebook changed their API/Policy again? Or what am I missing/not doing correctly there in the code?

推荐答案

(再次)他们已经改变了一切.在为Connect构建登录"按钮时,您可以请求生日许可,例如:

They have changed things up (again). When you build the Login button for Connect, you can request permission to the birthday, like:

文档说,一旦用户授权了您的网站,您就可以从用户的个人资料中获取这些字段..."

The documentation says, "Once the user authorizes your site, you can fetch those fields from the user's profile..."

http://developers.facebook.com/docs/guides/web#login

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

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