facebook api如何从user_location获取lat / long

时间:2015-01-01 19:39:13

标签: php facebook api location

这里有一个讨论:location (lat long) using facebook api但它并没有显示如何获得它......

我可以获得基本信息:

"location": {
 "id": "104146386288393", 
 "name": "Newton, Massachusetts"
   }, 

但如何使用位置ID提出请求

{
  "id": "104146386288393", 
  "name": "Newton, Massachusetts", 
  "picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQDygUYzFOcjhDoD&w=100&h=300&url=http\u00253A\u00252F\u00252Fupload.wikimedia.org\u00252Fwikipedia\u00252Fen\u00252Fe\u00252Fe6\u00252FNewton_City_Hall\u0025252C_Massachusetts.jpg&fallback=hub_city&prefix=s", 
  "link": "http://www.facebook.com/pages/Newton-Massachusetts/104146386288393", 
  "likes": 3741, 
  "category": "City", 
  "is_published": true, 
  "is_community_page": true, 
  "description": "<snipped data>", 
  "location": {
    "latitude": 42.3369, 
    "longitude": -71.2097
  }, 
  "checkins": 310, 
  "talking_about_count": 8912
}

这是我的Facebook代码:

$user_profile = (new FacebookRequest($session, 'GET', '/me?fields=id, first_name, location'))->execute()->getGraphObject(GraphUser::className());

感谢

2 个答案:

答案 0 :(得分:1)

这是你可以做的:

  • 使用user_location
  • 授权用户
  • /me?fields=location
  • 发出GET请求
  • /me
  • 的结果中的位置ID发出GET请求

...意思是,您只需要进行额外的API调用即可获得纬度/经度。

答案 1 :(得分:0)

您可以在实施前查看the graph api工具。

拥有位置ID后,您需要调用&#34; location_id&#34;?fields = location来获取长/ lat

enter image description here