关于 java:Spring Social for Facebook – 获取用户位置 | 珊瑚贝

Spring Social for Facebook – get user location


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

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

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

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


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

1
2
3
4
5
    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

  • 不幸的是,并不是所有的地方都遵循这个惯例,其中一些地方只包括城市,而不是国家。


来源:https://www.codenong.com/11591797/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9927.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?