Facebook Graph API:获取用户位置


Facebook Graph API: Get user location

我正在尝试使用此代码获取Facebook用户位置,但它不起作用:

        $user_fbid  = $fbuser;
        $user_email = $user_profile["email"];
        $user_fnmae = $user_profile["first_name"];
        $user_lnmae = $user_profile["last_name"];
        $user_lcity = $user_profile["location"]['name'];

所有其他字段都有效,但我无法获取用户的当前城市/国家/地区。知道问题出在哪里吗?

我改变了这个:

        $user_lcity = $user_profile["location"]['name'];

对此:

        $user_lcity = $user_profile["location"];

但仍然没有任何变化。

user_location添加到作用域

public_profile没有给你位置

检查这些。你可以尝试图形 API 资源管理器并在那里进行实验

https://developers.facebook.com/docs/facebook-login/permissions/v2.2#reference

https://developers.facebook.com/tools/explorer?method=GET&path=me%3Ffields%3Did%2Cname&version=v2.2

var_dump($user_profile);//look for location in the dumped data
1)If location array is not set then no data will be there, because user might not set his location in fb profile
2)You need to set permission in your app to access location.
https://developers.facebook.com/apps/