我们如何访问 facebook graph API 返回的位置的纬度和经度?
How do we access the latitude and longitude of a location returned by facebook graph API?
当我们进行此查询时,
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
再次请求
$user_profile = $facebook->api('/' + id,'GET');
这将 return 一个具有 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
当我们进行此查询时,
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
再次请求
$user_profile = $facebook->api('/' + id,'GET');
这将 return 一个具有 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