未在Spring社交Facebook上填充位置
我试图在Spring社交Facebook上获取用户位置:
Facebook fb = ((Facebook) connection.getApi());
Page pg = fb.pageOperations().getPage(fb.userOperations().getUserProfile().getLocation().getId());
  问题是pg.getLocation()返回null 。 
我也试过
fb.fetchObject(fb.userOperations().getUserProfile().getLocation().getId(), org.springframework.social.facebook.api.Location.class)
但它确实填充了名称,而不是国家或其他字段。
尝试使用图API API Explorer /v2.6/112286918797929?fields=id,name,location按预期返回:
{
  "id": "112286918797929",
  "name": "Sacele",
  "location": {
    "city": "Sacele",
    "country": "Romania",
    "latitude": 45.6167,
    "longitude": 25.6833
  }
}
这是Spring Social Facebook的问题吗?
我正在使用Spring Social 1.1.4和Spring Social Facebook 2.0.3。
我也尝试过Facebook的Spring Social - 获取用户位置,但不幸的是,并非所有的地方都遵循名称会议城市,国家和其中一些名称只包括城市,而不是国家。 另外你怎么能得到地理坐标?
  我终于明白了。  首先它不适用于PageOperations ,但它适用于GraphApi 。 
代码是
UserProfile userProfile = fb.userOperations().getUserProfile();
Page pg = fb.fetchObject(userProfile.getLocation().getId(), Page.class, "location");
  技巧是指定第三个参数,它代表字段(可以将多个字段指定为字符串)。  现在该页面已填充,您可以像pg.getLocation().getCountry()那样获取国家/地区。 
正如你所说,下面的命令
fb.fetchObject(fb.userOperations().getUserProfile().getLocation().getId(), org.springframework.social.facebook.api.Location.class)
给出响应来自参考的名称。
  这有2个公共方法: getId()和getName() 。 
  一些像getLocation()这样的方法取决于权限。  如果任何用户允许您查看他的位置,则可以访问此方法。 
从文档:
的getLocation
public Reference getLocation()
用户的位置。 仅适用于“user_location”或“friends_location”权限。
返回:a对用户位置的引用(如果可用)
代码示例:
  Page profile=facebookTemplate.pageOperations().getPage(id);
  String name=profile.getName();
  String webside=profile.getWebsite();
  String logo="http://graph.facebook.com/" + id + "/picture";
  party=new FullPoliticalParty(name,color,logo,webside);
  String phone=profile.getPhone() == null ? "No disponible" : profile.getPhone();
  party.setPhone(phone);
  org.springframework.social.facebook.api.Location loc=profile.getLocation();
  if (loc != null) {
    location=new LocationMapa(loc.getCity(),loc.getCountry(),loc.getStreet(),loc.getZip());
  }
  party.setLocation(location);
资源链接:
UPDATE1:
  我认为你需要通过Graph API的用户权限。  然后,您可以访问您向特定用户请求的位置或其他信息。  Checking Current Permissions并Handling Missing Permissions在此链接中给出。 
对于USER权限:
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{user-id}/permissions",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
对于用户权限,您可以阅读本教程
对于用户位置,您可以阅读本教程。
获得相关权限后,您还可以获得访问位置,经度,纬度和其他信息。
链接地址: http://www.djcxy.com/p/34525.html