【发布时间】:2012-09-06 20:12:20
【问题描述】:
我正在制作一个 facebook 应用程序来显示用户的生日............
<?
require_once('php-sdk/facebook.php');
$config = array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
?>
<html>
<head></head>
<body>
<?
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','GET');
echo "Name: " . $user_profile['name'];
// Birth Date to be printed here........
echo "DOB: ".$user_profile['birthday'];
}
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>';
}
?>
</body>
</html>
现在,问题是This prints the name as expected but prints nothing in place on date of birth.......当我进一步提到时,我听说了 facebook 权限(扩展)这个词......
并从以下链接
http://developers.facebook.com/docs/reference/api/user/
我发现我们需要启用权限users_birthday 或friends_birthday。
现在,我们如何在 php 代码中启用它??...请帮助提供示例...... 如果这个问题看起来很愚蠢,我很抱歉。我只是 facebook 应用程序开发的新手,也是 php 的初学者....... 我尝试了 stackoverflow.com 中的其他示例,但对我没有多大帮助......
【问题讨论】:
-
只是为了详细说明下面的 Igys 答案。使用 Graph api 时。默认情况下,FB 会询问的最少是用户的基本信息,以及属于基本信息类别的内容,例如名字和姓氏、会员 ID 等。除此之外的任何其他内容都是扩展信息或请求的特殊许可。单击 Igys 答案中的链接以了解范围及其使用方法的细分。
标签: php facebook facebook-graph-api user-profile