Facebook iFrame app - how to find the current city?

I am trying to migrate an old FBML application to iFrame using the new PHP SDK and GRAPH API, but I cannot figure out how to find a visitor city.

For example, in my own Facebook profile, I list both Current City and Hometown :

enter image description here

But when I try to use the following iFrame application, the location and hometown are not printed, but other data is printed, including my employers and education:

<?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);
    }
}

?>

Here is some of the data that I see for myself, the current location is not there:

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
...........
)

Relationship Alex

+3
source share
2

user_location user_hometown permissions.

, URL- - :

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

, , fb api ( FB)

   "id": "220439",
   "name": "Bret Taylor",
   "first_name": "Bret",
   "last_name": "Taylor",
   "link": "http://www.facebook.com/btaylor",
   "username": "btaylor",
   "hometown": {
      "id": "108363292521622",
      "name": "Oakland, California"
   },
   "location": {
      "id": "109650795719651",
      "name": "Los Gatos, California"
   },

, api

$me = $facebook->api('/me');

, " ". ( ) ""..

$hometown = $me['hometown']['name'];
$current_city = $me['location']['name'];

echo 'You are currently living in: '.$current_city.' but your hometown is: '.$hometown

hope it helps man ;)

EDIT:

            $access_token = $facebook->getAccessToken();
            $req_id = $_GET['request_ids'];
            $req = $facebook->api('/me/?access_token='.$access_token);
            echo $req['hometown']['name'];
+2

All Articles