java – Spring社交Facebook上没有填充位置
发布时间:2020-12-15 00:54:44 所属栏目:Java 来源:网络整理
导读:我正试图在 Spring Social Facebook获得用户位置: Facebook fb = ((Facebook) connection.getApi());Page pg = fb.pageOperations().getPage(fb.userOperations().getUserProfile().getLocation().getId()); 问题是pg.getLocation()返回null. 我也尝试过 fb
我正试图在
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()一样获得国家/地区. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |