Spring Social for Facebook - get user location

允我心安 提交于 2019-12-25 05:23:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!