How to retrieve user country using facebook Graph API?

前端 未结 4 1147
南旧
南旧 2020-12-30 03:13

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 coun

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 03:30

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

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

    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.

    The object will look something like this:

      "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": "<>"
      },
      "id": "112604772085346"
    }
    

提交回复
热议问题