checklist
checklist

Reputation: 12930

Spring Social for Facebook - get user location

I am using spring social Facebook to connect to facebook. The connection works well. I am trying to get the user's location with the following code:

FacebookProfile profile = facebook.userOperations().getUserProfile();
Reference rLocation = profile.getLocation();
Location location= facebook.fetchObject(rLocation.getId(), Location.class);

But what I get is an empty location object (it doesn't have any of the details). I can see that the rLocation does have a name (Los Angeles) but I also need the country.

Any idea how to get the actual Location object?

Upvotes: 0

Views: 1107

Answers (1)

Usha
Usha

Reputation: 1468

You can only get the location details that are a part of the Reference object which is the rLocation here. You can get the location city and location state but the location country is not a part of the Reference object.

    Reference rLocation = profile.getLocation();
    String locationName = rLocation.getName(); 
    String[] cityAndState = locationName.split(",");
    String city = cityAndState[0].trim();
    String state = cityAndState[1].trim();

The Location object basically helps to get the details of a user checked in location in facebook. Please refer to the spring social facebook API for more details.

http://static.springsource.org/spring-social-facebook/docs/1.0.x/api/org/springframework/social/facebook/api/Location.html

Upvotes: 1

Related Questions