0

我正在使用 spring social Facebook 连接到 facebook。连接效果很好。我正在尝试使用以下代码获取用户的位置:

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

但我得到的是一个空的位置对象(它没有任何细节)。我可以看到 rLocation 确实有一个名称(洛杉矶),但我还需要该国家/地区。

知道如何获取实际的 Location 对象吗?

4

1 回答 1

1

您只能获取作为参考对象一部分的位置详细信息,即此处的 rLocation。您可以获得位置城市和位置状态,但位置国家不是参考对象的一部分。

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

Location 对象基本上有助于获取用户在 facebook 中签入位置的详细信息。详情请参阅 spring social facebook API。

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

于 2012-11-02T16:02:46.673 回答