其余的代码正常工作,并返回我要查找的值。代码的最后两行不正确。根据我对Facebooks文档的理解(我可能误读了一些东西),位置对象确实存储经度和纬度,但我不知道如何访问这些东西。
以下是我的代码摘录:
$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 />";
对我来说,我目前取回了这个数据
"location": {
"id": "109873549031485",
"name": "Longmont, Colorado"
},
然后您可以使用获取id
id =['location']['id']
然后对进行另一个图形调用
$user_profile = $facebook->api('/' + id,'GET');
然后它将提供一个具有横向/纵向的对象
"location": {
"latitude": 40.1672,
"longitude": -105.101
},
您可以使用FQL查询来实现这一点。lat/lng字段无法通过Graph API获得。因此,您可以进行如下查询(假设您已经请求了这些字段/连接的适当权限):
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()
它给你一些类似的东西
{
"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 />";