Querying the Social Graph

Prerequisite

Check if User is a Friend

That’s how you check, if some user is a friend of the current user.

1
2
3
4
5
6
NSString *anotherUserId = anotherUser.userId;
[GetSocialUser isFriend:anotherUserId success:^(BOOL isFriend) {
    NSLog(@"Are %@ and %@ friends? %@", GetSocialUser.userId, anotherUserId, isFriend ? @"Yes" : @"No");
} failure:^(NSError *error) {
    NSLog(@"Exception while checking friendship: %@", error);
}];

Get Amount of Friends

You can get the amount of friends of the current user with the help of the following method.

1
2
3
4
5
[GetSocialUser friendsCountWithSuccess:^(int friendsCount) {
    NSLog(@"Amount of friends for current user: %d", friendsCount);
} failure:^(NSError *error) {
    NSLog(@"Exception while receiving friends count: %@", error);
}];

Get List of Friends

You can get the list of all friends of the current user page by page.
Use limit and offset to traverse multiple pages of friends.

1
2
3
4
5
6
7
8
9
int offset = 0;
int limit = 100;
[GetSocialUser friendsWithOffset:offset limit:limit success:^(NSArray<GetSocialPublicUser *> *friends) {
    for (GetSocialPublicUser *friend in friends) {
        NSLog(@"Received a friend: %@ %@", friend.userId, friend.displayName);
    }
} failure:^(NSError *error) {
    NSLog(@"Exception while receiving friends: %@", error);
}];

Suggested Friends

When user is building his social graph and creating connections with other users, GetSocial backend is finding the best possibile options to make new friendship for your user. As a result, we make a list of users, that are not directly connected to user, but have mutual friends with him. That means that these users could be friends with your user in real life, but they haven’t met in your game yet. With Suggested Friends functionality you can make building user’s social graph process much faster. Use it as described below:

1
2
3
4
5
6
7
8
9
int offset = 0;
int limit = 10;
[GetSocialUser suggestedFriendsWithOffset:offset limit:limit success:^(NSArray<GetSocialSuggestedFriend *> *friends) {
    for (GetSocialSuggestedFriend *friend in friends) {
        NSLog(@"Possible friend: %@ (%d mutual friends)", friend.displayName, friend.mutualFriendsCount);
    }
} failure:^(NSError *error) {
    NSLog(@"Exception while receiving suggested friends: %@", error);
}];

Give us your feedback! Was this article helpful?

😀 🙁