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;
}
Thanks!
To complete what Lix said:
You can do it with only one call to Graph API, by calling
/me?fields=name,email,gender,age_range,picture,location{location}
Indeed, the location object under the user object is a Page object, which has a Location object.
So, this will give you something like this:
"location": {
"location": {
"city": "Ramat Gan",
"country": "Israel",
"latitude": 32.0833,
"longitude": 34.8167,
"zip": "<<not-applicable>>"
}
}
This avoids you to make a double call to Graph API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With