我正在尝试使用新的 PHP SDK 和 GRAPH API 将 an old FBML app 迁移到 iFrame,但无法弄清楚 - 如何找到访问者的城市。

例如,在我自己的 Facebook 个人资料中,我列出了 当前城市 家乡 :

但是当我尝试以下 iFrame 应用程序时,没有打印 位置 家乡 ,而打印了包括我的雇主和教育在内的其他数据:

<?php

include_once 'facebook.php';

$facebook = new Facebook(array(
            'appId'  => "182820975103876",
            'secret' => "XXXXXXX",
            'cookie' => true,
            ));

$session = $facebook->getSession();

if (!$session) {
    $url = $facebook->getLoginUrl();
    print("<script type='text/javascript'>top.location.href = '$url';</script>");

} else {
    try {
        $me = $facebook->api('/me');

        print('<pre>');
        print_r($me);
        print('</pre>');

    } catch (FacebookApiException $e) {
        print("Error:" . $e);
    }
}

?>

这是我自己看到的部分数据,当前位置不存在:
Array
(
    [first_name] => Alexander
    [education] => Array
        (
            [0] => Array
                (
                    [school] => Array
                        (
                            [id] => 106509962720287
                            [name] => Riga Nr. 40
                        )

                    [type] => High School
                )

            [1] => Array
                (
                    [school] => Array
                        (
                            [id] => 103130426393616
                            [name] => RWTH Aachen University
                        )

                    [year] => Array
                        (
                            [id] => 143018465715205
                            [name] => 2000
                        )

                    [type] => College
                )

        )
    [gender] => male
...........
)

问候
亚历克斯

最佳答案

您只需要 user_locationuser_hometown permissions

所以你的登录网址应该是这样的:

$url = $facebook->getLoginUrl(array(
    'scope' => 'user_location,user_hometown'
));

关于Facebook iFrame 应用程序 - 如何查找用户当前所在的城市?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5911425/

10-12 01:16
查看更多