Facebook Graph API:获取用户位置

时间:2014-11-14 11:53:48

标签: php facebook facebook-graph-api

我试图通过此代码获取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"];

但仍然没有变化。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:-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/