facebook api 如何从 user_location 获取 lat/long

facebook api how to get lat/long from user_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());

谢谢

这是你可以做的:

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

...意思是,您只需要执行额外的 API 调用即可获得 latitude/longitude.

您可以在实施前使用 the graph api 工具进行检查。

获得location id后,需要调用"location_id"?fields=location获取long/lat