facebook未填

java – Spring Social Facebook 上未填充位置,我正在尝试获取 Spring Social 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)
但它只填充名称,不填充国家或其他字段。

在 Graph 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。

我也试过 Spring Social for Facebook – get user location ,但不幸的是,并非所有地方都遵循名称约定 City, Country 并且其中一些名称中仅包含城市,而不包含国家/地区。另外,您如何获得地理坐标?

最佳答案

我终于明白了。首先,它不适用于 PageOperations,但它适用于 GraphApi。

代码是

UserProfile userProfile = fb.userOperations().getUserProfile();
Page pg = fb.fetchObject(userProfile.getLocation().getId(), Page.class, “location”);
诀窍是指定第三个参数,它表示字段(您可以将多个字段指定为字符串)。现在页面已填充,您可以像 pg.getLocation().getCountry() 一样获取国家/地区。

Add a Comment

您的电子邮箱地址不会被公开。 必填项已用*标注