0

I am using spring social to get a list of all the my friends. However, it seems that the number of friends I can get from the facebook graph api is not the same as the number of friends that facebook reports on my profile.

According to facebook I have 175 friends. Using spring social facebook I can only seem to get 156 friends. I know about the paging issues with spring social facebook so I am using the code below.

private Map<String, FacebookProfile> getFacebookProfiles()
{
    Connection<Facebook> connection = connectionRepository.findPrimaryConnection(Facebook.class);
    FriendOperations friendOperations = connection.getApi().friendOperations();

    // FindFriendProfes() only returns 100 friends, need to use batching to get all friends 
    List<FacebookProfile> friendProfiles = new ArrayList<>(250);
    final int batchSize = 100;
    int offset = 0;
    List<FacebookProfile> batch = friendOperations.getFriendProfiles(offset, batchSize);
    do
    {
        friendProfiles.addAll(batch);
        offset = offset + batchSize;
        batch = friendOperations.getFriendProfiles(offset, batchSize);
    } while (batch.size() != 0);

    Map<String, FacebookProfile> result = new HashMap<>(friendProfiles.size());
    for (FacebookProfile facebookProfile : friendProfiles)
    {
        result.put(facebookProfile.getId(), facebookProfile);
    }

    return result;
}

Either there is a bug in spring-social facebook integration or there is a way for facebook users to say that they should not be returned as part of graph api call.

Can a facebook user opt of being returned as a friend from the graph api?

ams
  • 60,316
  • 68
  • 200
  • 288

1 Answers1

1

Yes precisely, Facebook users can opt out of third party applications by going to their Privacy Settings > Ads, Apps and Websites > Edit Settings > How people bring your info to apps they use

Those friends who edited those settings will not show up in your graph API calls.

Jesse Chen
  • 4,928
  • 1
  • 20
  • 20