I'm trying to get user location in Spring Social Facebook:
Facebook fb = ((Facebook) connection.getApi());
Page pg = fb.pageOperations().getPage(fb.userOperations().getUserProfile().getLocation().getId());
The problem is that pg.getLocation()
returns null
.
I also tried with
fb.fetchObject(fb.userOperations().getUserProfile().getLocation().getId(), org.springframework.social.facebook.api.Location.class)
but it does populate only the name, not country or other fields.
Trying on Graph API Explorer /v2.6/112286918797929?fields=id,name,location returns as expected:
{
"id": "112286918797929",
"name": "Sacele",
"location": {
"city": "Sacele",
"country": "Romania",
"latitude": 45.6167,
"longitude": 25.6833
}
}
Is this an issue with Spring Social Facebook?
I'm using Spring Social 1.1.4 and Spring Social Facebook 2.0.3.
I also tried Spring Social for Facebook - get user location, but unfortunately not all the places follow the name convention City, Country and some of them include in the name only the city, not the country too. Plus how can you get the geo-coordinates?
I finally got it. First of all it doesn't work with PageOperations
, but it works with GraphApi
.
And the code is
UserProfile userProfile = fb.userOperations().getUserProfile();
Page pg = fb.fetchObject(userProfile.getLocation().getId(), Page.class, "location");
The trick is specifying the third parameter, which represents the fields (you can specify multiple fields as strings). Now the page is populated and you can get the country like pg.getLocation().getCountry()
.
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