生日约会不起作用

时间:2013-03-04 10:58:33

标签: facebook date get

我正在开发一个应用程序来获取用户的生日日期,但它仍然无效。 最奇怪的是,当我调试这个应用程序抛出开发人员的Facebook界面,它的工作完美。 所以我不知道为什么不想工作。 这是我获得生日的PHP代码:

<?php
if($user_id) {

  // We have a user ID, so probably a logged in user.
  // If not, we'll get an exception, which we handle below.
  try {

    $user_profile = $facebook->api('/me?fields=id,name,birthday', 'GET');
    print_r($user_profile);
    //echo "Name: " . $user_profile['name'];

  } catch(FacebookApiException $e) {
    // If the user is logged out, you can have a 
    // user ID even though the access token is invalid.
    // In this case, we'll get an exception, so we'll
    // just ask the user to login again here.
    $login_url = $facebook->getLoginUrl(); 
    echo 'Please <a href="' . $login_url . '">login.</a>';
    error_log($e->getType());
    error_log($e->getMessage());
  }   
} else {

  // No user, print a link for the user to login
  $login_url = $facebook->getLoginUrl();
  echo 'Please <a href="' . $login_url . '">login.</a>';

}

&GT;

感谢任何人

1 个答案:

答案 0 :(得分:0)

正如CBroe所述,您的权限范围需要user_birthday

$params = array(
  'scope' => 'user_birthday',
  'redirect_uri' => 'https://www.myapp.com/post_login_page'
);

$loginUrl = $facebook->getLoginUrl($params);