2016-07-27 49 views
1

我想要獲得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_profileemail

在一些例子中我發現,權限可以添加: enter image description here

我沒有發現這樣的事。在我的應用程序設置,我發現只有這個頁面下的「應用程序審查」

enter image description here

這裏是user_friends「活並供用戶」

  1. 我做了什麼錯誤或如何實際使用這個「默認授予「使用Spring Social的權限?
  2. 我該如何請求像user_posts這樣的額外權限並在Spring框架中使用它們?
+1

它只會將那些授予user_friends權限的朋友返回給應用程序。我的猜測是,你沒有要求它 – WizKid

+0

我明白,它只會返回這些用戶。我有3-4個用戶在我的應用程序中使用FB登錄。如第二張截圖所示,「approved items」中有'user_friends',但它不會通過'facebook.userOperations()。getUserPermissions()'方法返回此權限。我問的是如何使用這個權限(應該默認授予)並要求/添加新的權限。 –

+1

您閱讀Facebook登錄文檔,瞭解如何獲得權限 – WizKid

回答

1

我的問題的解決方案非常簡單。如果有人遇到同樣的問題,請在Facebook登錄按鈕中向FB定義應用程序的權限。

這樣的事情取決於你的情況。

<fb:login-button scope="public_profile,email,user_friends" onlogin="checkLoginState();"> 
</fb:login-button> 

剛接觸這個,只是使用登錄按鈕示例代碼沒有審查和thoght權限定義在應用程序設置。

+0

請幫忙拿空白沒有照片。試圖添加鏈接,但沒有任何好處只有擁有授權照片的用戶才能進入我的頁面http://way2enjoy.com/facebook-fun – Steeve

+0

plz help如果您可以幫助 – Steeve

相關問題