Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve zip code of a facebook user by facebook graph API

I am trying to retrieve Zip code of a user using facebook graph API. I am using follow code for that. Code is in php.

$facebook = new Facebook(array(
            'appId' => APP_ID,
            'secret' => APP_SECRET,
            ));

$user = $facebook->getUser();
//$login_url = $facebook->getLoginUrl(array( 'scope' => 'email'));
$login_url   = $facebook->getLoginUrl(
           array(
               'scope'         => 'email,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown'
           )
   );
//get user basic description
//$userInfo           = $facebook->api("/$user");

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }

Here I am getting the $user_profile array, It has all information other that zip code. But I gave permission for that. Is there any way to get zip code from facebook.

like image 363
Amar Banerjee Avatar asked Oct 21 '22 07:10

Amar Banerjee


1 Answers

If you check the documentation for the /me call at https://developers.facebook.com/docs/reference/api/user/ you'll note that there is no reference to the user's zip or postal code.

I'd recommend you use ask for the user_location permission and then call /me?fields=location and try to derive the zip code from the information contained therein - this answer https://stackoverflow.com/a/7129344/2091159 - has some information about doing so.

like image 109
Reuben Thompson Avatar answered Oct 27 '22 22:10

Reuben Thompson