我们如何访问facebook图API返回的位置的纬度和经度?

时间:2016-06-11 21:02:13

标签: javascript python facebook facebook-graph-api facebook-javascript-sdk

当我们进行此查询时,

me?fields=location

返回的数据是

{
  "location": {
    "id": "152971558114865",
    "name": "Kharagpur"
  },
  "id": "884016091689459"
}

我的问题是如何使用位置ID获取此地点的纬度和经度?

我知道我需要为它进行此查询。但我无法理解如何使用这个?

GET v2.6/...?fields={fieldname_of_type_Location} HTTP/1.1 Host: graph.facebook.com

有人可以为此查询编写确切的代码吗?

修改

我写了这段代码:

function testAPI() {
    FB.api('/me', {fields: "id,birthday,email,gender,location,name"},function(response) {
  });


/* make the API call */
FB.api("...?fields={response.location}",
function (response2) {
  console.log(response2);
}
);
}

我在response2中收到错误。

message : Some of the aliases you request do not exist. 
type: OAuth Exception 

1 个答案:

答案 0 :(得分:1)

再提出

等请求
$user_profile = $facebook->api('/' + id,'GET');

这将返回具有lat / lang

的对象
"location": {
   "latitude": ... , 
   "longitude": ...
}, 

<强>编辑:

javaScript代码将是这样的(仅在facebook的Graph API工具资源管理器上测试):

function testAPI() {
    FB.api('/me', {
        fields: 'id,birthday,email,gender,location,name'
    }, function(response) {
        var location = reponse.location; //gets the location object you get from your response now
        FB.api('/' + location.id, {
            fields: 'location'
        }, function(locationResponse) {
            console.log(locationResponse); //will print your desired location object
        });

    });

如果你想探索它,你可以here