0

我正在开发一个获取用户生日日期的应用程序,但它仍然无法正常工作。最奇怪的是,当我调试这个应用程序时,它会抛出开发者 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>';

}

?>

感谢任何人

4

1 回答 1

0

正如 CBroe 所指出的,您需要user_birthday在您的权限范围内

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

$loginUrl = $facebook->getLoginUrl($params);
于 2013-06-19T18:13:34.613 回答