我想要獲得FB朋友列表。我知道它只會返回那些也在使用該應用的用戶。如何使用Spring Social獲取Facebook朋友列表
我做了應該返回好友列表的REST點。下面是修改後的代碼進行測試:
@RequestMapping(value = "/fbfriends",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public List<User> GetFriends(Connection<?> connection) {
log.debug("REST request to get all Friends");
if (connection == null) {
log.error("Cannot create social user because connection is null");
throw new IllegalArgumentException("Connection cannot be null");
}
log.debug("Got connection");
List<Permission> permissions = facebook.userOperations().getUserPermissions();
log.debug("Permission size: " + permissions.size() + " Permission: " + permissions);
for (Permission perm: permissions){
log.debug(perm.getName() + " " + perm.getStatus());
}
List<User> friends = facebook.friendOperations().getFriendProfiles();
log.debug("Friends size: " + friends.size() + " Friends:" + friends.toString());
PagedList<Post> feed = facebook.feedOperations().getFeed();
log.debug("Feed size: " + feed.size() + " Feed: " + feed.toString());
PagedList<UserTaggableFriend> taggable = facebook.friendOperations().getTaggableFriends();
log.debug("Taggable size: " + friends.size() + " Taggable:" + friends.toString());
log.debug("Ho Ho Ho");
return friends;
}
所有這些log.debug
只是對我來說,這裏是結果:
2016-07-27 17:38:22.443 DEBUG 10828 --- [nio-8080-exec-1] c.m.myapp.aop.logging.LoggingAspect : Exit: org.springframework.social.connect.ConnectionRepository.findPrimaryConnection() with result = [email protected]b877
2016-07-27 17:38:22.581 DEBUG 10828 --- [nio-8080-exec-1] c.m.myapp.web.rest.FbFriendResource : Permission size: 2 Permission: [[email protected], [email protected]]
2016-07-27 17:38:22.581 DEBUG 10828 --- [nio-8080-exec-1] c.m.myapp.web.rest.FbFriendResource : email granted
2016-07-27 17:38:22.581 DEBUG 10828 --- [nio-8080-exec-1] c.m.myapp.web.rest.FbFriendResource : public_profile granted
2016-07-27 17:38:22.694 DEBUG 10828 --- [nio-8080-exec-1] c.m.myapp.web.rest.FbFriendResource : Friends size: 0 Friends:[]
2016-07-27 17:38:22.739 DEBUG 10828 --- [nio-8080-exec-1] c.m.myapp.web.rest.FbFriendResource : Feed size: 0 Feed: []
2016-07-27 17:38:22.788 DEBUG 10828 --- [nio-8080-exec-1] c.m.myapp.web.rest.FbFriendResource : Taggable size: 0 Taggable:[]
2016-07-27 17:38:22.789 DEBUG 10828 --- [nio-8080-exec-1] c.m.myapp.web.rest.FbFriendResource : Ho Ho Ho
2016-07-27 17:38:22.798 DEBUG 10828 --- [nio-8080-exec-1] c.m.myapp.aop.logging.LoggingAspect : Exit: com.mycompany.myapp.web.rest.FbFriendResource.GetFriends() with result = []
正如你可以看到有隻有兩個授予的權限:public_profile
和email
。
我沒有發現這樣的事。在我的應用程序設置,我發現只有這個頁面下的「應用程序審查」
這裏是user_friends
「活並供用戶」
- 我做了什麼錯誤或如何實際使用這個「默認授予「使用Spring Social的權限?
- 我該如何請求像
user_posts
這樣的額外權限並在Spring框架中使用它們?
它只會將那些授予user_friends權限的朋友返回給應用程序。我的猜測是,你沒有要求它 – WizKid
我明白,它只會返回這些用戶。我有3-4個用戶在我的應用程序中使用FB登錄。如第二張截圖所示,「approved items」中有'user_friends',但它不會通過'facebook.userOperations()。getUserPermissions()'方法返回此權限。我問的是如何使用這個權限(應該默認授予)並要求/添加新的權限。 –
您閱讀Facebook登錄文檔,瞭解如何獲得權限 – WizKid