Adr*_*Ber 7 java facebook-graph-api spring-social spring-social-facebook
我正试图在Spring Social Facebook中获得用户位置:
Facebook fb = ((Facebook) connection.getApi());
Page pg = fb.pageOperations().getPage(fb.userOperations().getUserProfile().getLocation().getId());
Run Code Online (Sandbox Code Playgroud)
问题是pg.getLocation()退货null.
我也尝试过
fb.fetchObject(fb.userOperations().getUserProfile().getLocation().getId(), org.springframework.social.facebook.api.Location.class)
Run Code Online (Sandbox Code Playgroud)
但它只填充名称,而不是国家或其他领域.
尝试使用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
}
}
Run Code Online (Sandbox Code Playgroud)
这是Spring Social Facebook的问题吗?
我正在使用Spring Social 1.1.4和Spring Social Facebook 2.0.3.
我也试过Spring社交Facebook - 获取用户位置,但遗憾的是并非所有地方都遵循名称约定城市,国家,其中一些仅包括名称城市,而不是国家.另外你怎么能得到地理坐标?
我终于明白了。首先,它不能与 一起使用PageOperations,但可以与 一起使用GraphApi。
代码是
UserProfile userProfile = fb.userOperations().getUserProfile();
Page pg = fb.fetchObject(userProfile.getLocation().getId(), Page.class, "location");
Run Code Online (Sandbox Code Playgroud)
诀窍是指定第三个参数,它代表字段(您可以将多个字段指定为字符串)。现在页面已填充,您可以获取国家/地区,例如pg.getLocation().getCountry()。