Get facebook user zip with facebook graphic API

I am trying to get a user zip using facebook API. I use the following code for this. The 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 authenticated. $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); $user = null; } 

Here I get an array of $ user_profile, it has all the information, other information about the zip code. But I gave permission for this. Is there any way to get the zip code from facebook.

+4
source share
2 answers

If you check the documentation for calling /me at https://developers.facebook.com/docs/reference/api/user/ , you will notice that there is no link to the user postcode or postcode.

I would recommend you use the user_location request and then call /me?fields=location and try to get the zip code from the information it contains - this answer fooobar.com/questions/398697 / ... - there is information about this.

+3
source

This is the equivalent of JavaScript you want, I think:

 FB.api('/me', function(user){ FB.api('/' + user.location.id, function(location){ alert(location.location.zip); }); }) 
0
source

Source: https://habr.com/ru/post/1487263/


All Articles