0

我有一个基于此身份验证代码的非常简单的 Facebook 应用程序:

$session = $facebook->getUser();

if (!$session) {
    $url = $facebook->getLoginUrl(array(
               'canvas' => 1,
               'fbconnect' => 0,
               'scope' => 'publish_stream, email, user_activities, user_birthday, user_hometown'
               //'req_perms' => 'publish_stream,email,user_location,user_birthday,user_hometown'
           ));
    echo "<script type='text/javascript'>top.location.href = 'FB_URL';</script>";
} else {
    try {
        $uid = $facebook->getUser();
        $me = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        echo "<script type='text/javascript'>top.location.href = 'FB_URL';</script>";
    exit;
    } 
}

echo "\n === \n";
print_r($uid);
echo "\n === \n";
print_r($me);

输出是:

=== ID_VALUE === Array ( [id] => ID_VALUE [name] => NAME [first_name] => FIRST_NAME [last_name] => LAST_NAME [link] => PROFILE_URL [username] => USERNAME [gender] => male [email] => EMAIL [timezone] => 2 [locale] => en_US [verified] => 1 [updated_time] => 2012-05-16T13:00:04+0000 )

我希望在指定扩展权限后user_birthdayuser_hometown我还应该在数组中获取有关用户生日和家乡的信息……但不幸的是,这些信息在那里丢失了……

我错过了什么或者我做错了什么?

4

1 回答 1

4

我做了一些调查,

你可以试试这个: $me = $facebook->api('/me?fields=birthday');

对于范围 - 您请求正确的权限,它是user_birthday

确保你的$facebook对象有access_token

看看并报告,我会尽力提供帮助。

编辑:我不明白你从哪里得到 FB_URL,因为你在$url变量中写了 LoginUrl 我查看了你的代码并建议你尝试这种方式:

if (!$session) {
    $url = $facebook->getLoginUrl(array(
              'redirect_uri' => //SET back to your page or whenever you need
               'scope' => 'publish_stream, email, user_activities, user_birthday, user_hometown'          
           ));
    echo '<script type="text/javascript">top.location.href =' . $url . '</script>';
} else {
    try {           
        $me = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        echo $e->getMessage();       
    } 
}

另外验证所有权限的用户访问令牌 Get $facebook->getAccessToken(); 并在此处调试 ->令牌调试器

于 2012-09-05T10:36:50.063 回答