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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With