如何使用Facebook Graph API检索用户国家? [英] How to retrieve user country using facebook Graph API?

查看:178
本文介绍了如何使用Facebook Graph API检索用户国家?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索已登录的用户国家,并将其插入到div中。
我成功地使用用户名,性别和年龄范围,但是我不能检索国家。
这是我的代码:

I want to retrieve the logged in user country, and insert it into a div. I succeed making it with the user Name, Gender and Age range, but somewhy I can't retrieve the country. Here is my code:

  function testAPI() {
console.log('Welcome!  Fetching your information.... ');
FB.api('/me?fields=name,email,gender,age_range,picture,country', function (response) {
  document.getElementById('status').innerHTML = response.name + ",";
  document.getElementById('status1').innerHTML = response.gender + ",";
  document.getElementById('status2').innerHTML = (response.age_range.min) + "-" + (response.age_range.min + 1) + " years old";
  document.getElementById('status3').innerHTML = response.country;
}

谢谢!

推荐答案

我相信您要查找的参数是位置而不是国家。

I believe the parameter you are looking for is location instead of country.

/me?fields=name,email,gender,age_range,picture,location

为了查询这些数据,您需要您的用户授予您 user_location permiss离开

In order to query this data, you'll need your users to grant you the user_location permission.

这将给你用户提交的字段的价值 - 注意,这个参数可能不总是被填充,因为它取决于用户实际提交这个信息 - 如果没有提供 - 你将无法检索它。

This will give you value of the user submitted field - take note that this parameter might not always be populated since it depends on the user actually submitting this information - if they have not provided it - you will not be able to retrieve it.

该对象将如下所示:

  "location": {
    "id": "112604772085346",
    "name": "Ramat Gan"
  },

一旦你有位置对象(这很可能是一个页面),你可以查询对象检索国家:

Once you have the location object (which will most likely be a page), you can query that object to retrieve the country:

/112604772085346?fields=location

这将给你更多的信息,包括国家。

This will give you more information including the country.

{
  "location": {
    "city": "Ramat Gan",
    "country": "Israel",
    "latitude": 32.0833,
    "longitude": 34.8167,
    "zip": "<<not-applicable>>"
  },
  "id": "112604772085346"
}

这篇关于如何使用Facebook Graph API检索用户国家?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆