问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/11591797/spring-social-for-facebook-get-user-location