Php 使用Facebook graph API,是否可以从location对象获取经度和纬度?

Php 使用Facebook graph API,是否可以从location对象获取经度和纬度?,php,html,facebook,facebook-graph-api,Php,Html,Facebook,Facebook Graph Api,其余的代码工作并返回我正在寻找的值。代码的最后两行不正确。根据我对Facebooks文档的理解(我可能误读了一些东西),location对象确实存储经度和纬度,但我不知道如何访问这些东西 以下是我的代码摘录: $user_profile = $facebook->api('/me','GET'); echo "Name: " . $user_profile['name'] . "<br />"; echo "Gender: : " . $user_profile['ge

其余的代码工作并返回我正在寻找的值。代码的最后两行不正确。根据我对Facebooks文档的理解(我可能误读了一些东西),location对象确实存储经度和纬度,但我不知道如何访问这些东西

以下是我的代码摘录:

 $user_profile = $facebook->api('/me','GET');
 echo "Name: " . $user_profile['name'] . "<br />";
 echo "Gender: : "  . $user_profile['gender'] . "<br />";
 echo "Birthday: " . $user_profile['birthday']. "<br />";
 echo "Religion: " . $user_profile['religion']. "<br />";
 echo "Hometown: " . $user_profile['hometown']['name']. "<br />";
 $locationName = $user_profile['location']['name'];
 echo "Location: " . $location . "<br />";
 echo "Longitude: " . $user_profile['location']['']. "<br />";
 echo "Latitude: " . $user_profile['location']['']. "<br />";
$user_profile=$facebook->api('/me','GET');
回声“名称:”$用户配置文件['name']。“
”; 回声“性别::”$用户配置文件[‘性别’]。“
”; 回声“生日:”$用户配置文件[‘生日’]。“
”; 呼应“宗教:”$用户_档案[‘宗教’]。“
”; 回声“故乡:”$用户配置文件['homerium']['name']。“
”; $locationName=$user_profile['location']['name']; 回声“位置:”$地点。“
”; 回声“经度:”$用户配置文件['location'][']。“
”; 回声“纬度:”$用户配置文件['location'][']。“
”;
对于我来说,我目前正在取回这些数据

  "location": {
    "id": "109873549031485", 
    "name": "Longmont, Colorado"
  }, 
然后,您可以使用

id =['location']['id']
然后再调用另一个图形调用

$user_profile = $facebook->api('/' + id,'GET');
然后将提供一个具有lat/long的对象

 "location": {
    "latitude": 40.1672, 
    "longitude": -105.101
  }, 

您可以使用FQL查询来实现这一点。lat/lng气田无法通过Graph API获得。因此,您可以进行如下查询(假设您已请求对这些字段/连接的适当权限):

这给了你类似的东西

{
  "data": [
    {
      "name": "TestUser",
      "sex": "male",
      "birthday": "February 7, 1980",
      "religion": "Catholic",
      "hometown_location": {
        "city": "berlin",
        "latitude": 42.2544,
        "longitude": 8.84583
      },
      "current_location": {
        "city": "Paris",
        "latitude": 55.25,
        "longitude": 12.4
      }
    }
  ]
}
您需要将代码更改为

$user_profile= $facebook->api( array(
                         'method' => 'fql.query',
                         'query' => 'select name, sex, birthday, religion, hometown_location.city, hometown_location.latitude, hometown_location.longitude, current_location.city, current_location.latitude, current_location.longitude from user where uid=me()',
                     ));
echo "Name: " . $user_profile['name'] . "<br />";
echo "Gender: : "  . $user_profile['sex'] . "<br />";
echo "Birthday: " . $user_profile['birthday']. "<br />";
echo "Religion: " . $user_profile['religion']. "<br />";
echo "Hometown City: " . $user_profile['hometown_location']['city']. "<br />";
echo "Hometown Lat: " . $user_profile['hometown_location']['latitude']. "<br />";
echo "Hometown Lng: " . $user_profile['hometown_location']['longitude ']. "<br />";
echo "Current City: " . $user_profile['current_location']['city']. "<br />";
echo "Current Lat: " . $user_profile['current_location']['latitude']. "<br />";
echo "Current Lng: " . $user_profile['current_location']['longitude ']. "<br />";
$user\u profile=$facebook->api(数组)(
'方法'=>'fql.query',
'查询'=>'从uid=me()的用户中选择姓名、性别、生日、宗教、家乡位置.城市、家乡位置.纬度、家乡位置.经度、当前位置.城市、当前位置.纬度、当前位置.经度,
));
回声“名称:”$用户配置文件['name']。“
”; 回声“性别::”$用户配置文件['sex']。“
”; 回声“生日:”$用户配置文件[‘生日’]。“
”; 呼应“宗教:”$用户_档案[‘宗教’]。“
”; 呼应“家乡城市:”$用户配置文件['家乡位置]['城市]]。“
”; 回声“家乡拉特:”$用户配置文件['家乡位置]['纬度]]。“
”; 回声“家乡液化天然气:”$用户配置文件['家乡位置]['经度]]。“
”; 回声“当前城市:”$用户配置文件['当前位置]['城市]]。“
”; 回显“当前Lat:”$用户配置文件['current_location']['latitude']。“
”; 回声“当前液化天然气:”$用户配置文件['当前位置]['经度]]。“
”;
var\u dump($user\u profile)
将显示您需要处理的内容……“非默认”表示用户没有授予访问数据的权限(“user\u状态”)!而且,对于用户来说没有位置字段并不是真的,它只是不包含lat/lng这实际上是我已经尝试过的事情。然而,在我抓取位置id并尝试再次调用经度后,它会返回任何内容。经过一些修补后,我抓取了经度和纬度。谢谢你的帮助抱歉,如果我看起来有点迷路,但我对FQL不太了解。我准确地复制了代码,没有得到任何数据。我还缺什么吗?可能有权限吗?还有什么关于FQL的好文件是你告诉我的吗?谢谢你的帮助!好吧,你已经接受了另一个答案,所以我想这不再有兴趣…截至2016年8月8日,FQL将不再可用,无法查询。
$user_profile= $facebook->api( array(
                         'method' => 'fql.query',
                         'query' => 'select name, sex, birthday, religion, hometown_location.city, hometown_location.latitude, hometown_location.longitude, current_location.city, current_location.latitude, current_location.longitude from user where uid=me()',
                     ));
echo "Name: " . $user_profile['name'] . "<br />";
echo "Gender: : "  . $user_profile['sex'] . "<br />";
echo "Birthday: " . $user_profile['birthday']. "<br />";
echo "Religion: " . $user_profile['religion']. "<br />";
echo "Hometown City: " . $user_profile['hometown_location']['city']. "<br />";
echo "Hometown Lat: " . $user_profile['hometown_location']['latitude']. "<br />";
echo "Hometown Lng: " . $user_profile['hometown_location']['longitude ']. "<br />";
echo "Current City: " . $user_profile['current_location']['city']. "<br />";
echo "Current Lat: " . $user_profile['current_location']['latitude']. "<br />";
echo "Current Lng: " . $user_profile['current_location']['longitude ']. "<br />";