如何使用Spring Social获取Facebook好友列表

时间:2016-07-27 15:45:38

标签: spring facebook facebook-graph-api jhipster spring-social

我正在尝试获取FB好友列表。我知道它只会返回那些也使用该应用程序的人。

我做了REST点,应该返回好友列表。以下是测试的修改代码:

var tableView1: UITableView?
var tableview2: UITableView?


    // MARK: - Table view data source

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    if tableView == tableView1 {

        return 2;

    } else if tableView == tableview2 {

        return 3
    }
    return 0;

}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    if tableView == tableView1 {
        return 2;

    } else if tableView == tableview2 {

        return 1;
    }
    return 0;

}



func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
    if tableView == tableView1 {
        cell = tableView.dequeueReusableCellWithIdentifier("testcell1", forIndexPath: indexPath) as! UITableViewCell

    } else if tableView == tableview2 {

        cell = tableView.dequeueReusableCellWithIdentifier("testcell2", forIndexPath: indexPath) as! UITableViewCell
    }

    // Configure the cell...
    if tableView == tableView1 {

    cell.textLabel?.text = "Homeroom"
    cell.detailTextLabel?.text = "8:15 AM - 9:00 AM"
    cell.selectionStyle = .None

    } else if tableView == tableview2 {
        cell.textLabel?.text = "Test Table 2 "
        cell.detailTextLabel?.text = "1:30 PM - 2:30 PM"
        cell.selectionStyle = .None

    }

    return cell

}


//**Center collection cells in the middle**

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
    let sideInset = (collectionView.frame.size.width - 650) / 2
    return UIEdgeInsets(top: 0, left: sideInset, bottom: 0, right: sideInset)
}

}

//Card Scrolling datasource 

extension SAHomeViewController: UICollectionViewDataSource {

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    return 1
}

    //Number of cards on home screen
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 2
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cardcell", forIndexPath: indexPath)

    // Configure collection view cell

    return cell
}

所有这些dfr = sqlContext.read.format("com.mongodb.spark.sql.DefaultSource") df = dfr.option("pipeline", "[{ $limit: 10 }]").load() 仅供我使用,结果如下:

@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.debug2016-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 = org.springframework.social.connect.support.OAuth2Connection@99deb877 2016-07-27 17:38:22.581 DEBUG 10828 --- [nio-8080-exec-1] c.m.myapp.web.rest.FbFriendResource : Permission size: 2 Permission: [org.springframework.social.facebook.api.Permission@8fbfe4, org.springframework.social.facebook.api.Permission@5328b7d2] 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 = []

在某些示例中,我发现可以添加权限: enter image description here

我没有发现这样的事情。在我的应用程序设置中,我在&#34; App Review&#34;

下找到了此页面

enter image description here

以下是public_profile&#34;实时且可供用户使用&#34;

  1. 我做错了什么或如何实际使用这个&#34;默认授予&#34;使用Spring Social的权限?
  2. 我如何要求email等其他权限并在Spring Framework中使用它们?

1 个答案:

答案 0 :(得分:1)

我的问题的解决方案非常简单。如果有人遇到同样的问题,请在Facebook登录按钮上向FB中定义的应用程序的权限。

这样的事情取决于你的情况。

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

对此很新,只是使用示例代码登录按钮而不审核,并且在应用程序设置中定义了权限。