Reputation: 1143
Not sure if anyone else has expeienced a similiar issue when using the Facebook-PHP-SDK v5 . To retrieve user profile items such as name,first_name, last_name..etc. I have the following call.
public function getProfile(){
try {
$profile_request = $this->fb->get('/me?fields=name,first_name,last_name,email,gender,relationship_status, birthday, location');
$profile = $profile_request->getGraphNode()->asArray();
return $profile;
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
session_destroy();
// redirecting user back to app login page
header("Location: ./");
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
this is being called in my index.php page as follows:
$profile = $fblink->getProfile();
print_r($profile);
Now the strange this is, all of the users data is being printed Except for the users location. I have checked my permission in my app and Users_location has been enabled. I'm not recieving an error of any kind so i can't seem to find a reason for why this isn't being returned.
If anyone knows an easy workaround to return locations, this would be of great help. Or if anyone could shed some light why locations aren't being returned, this would be equally as helpful. Thanks
Upvotes: 2
Views: 74
Reputation: 6871
It may be that the user in your example has not set a location. Alternatively, does your app explicitly request privileges from the User to access location? If it does not, I believe facebook limits certain information that you can gather to avoid the privacy implications of such. As a result you'll need to set up an app on facebook, and then when a user goes to log in on your site, explicitly request access to certain information like location etc.
Here is a link to permissions you can request through the login feature: https://developers.facebook.com/docs/facebook-login/permissions how to request permissions: https://developers.facebook.com/docs/facebook-login/permissions/requesting-and-revoking
Upvotes: 1