Querying the Social Graph

Prerequisite

Check if User is a Friend

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

1
2
3
4
5
6
7
8
var anotherUserId = user.Id;
GetSocial.User.IsFriend (anotherUserId, 
    isFriend => {
        Debug.Log ("Are " + GetSocial.User.getId() + " and " + anotherUserId + " friends? " + isFriend);
    },
    error => {
        Debug.Log ("Exception while checking friendship: " + error.Message);
    });

Get Amount of Friends

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

1
2
3
4
5
6
7
GetSocial.User.GetFriendsCount ( 
    friendsCount => {
        Debug.Log ("Amount of friends for current user: " + friendsCount);
    },
    error => {
        Debug.Log ("Exception while receiving friends count: " + error.Message);
    });

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
10
11
var offset = 0;
var limit = 100;            
GetSocial.User.GetFriends(offset, limit,
    friends => {
        foreach (var friend in friends) {
            Debug.Log ("Received a friend: " + friend.Id + " " + friend.DisplayName);
        }
    },
    error => {
        Debug.Log ("Exception while receiving friends: " + error.Message);
    });

Suggested Friends

When the user is building his social graph and creating connections with other users, GetSocial backend is finding the best possible options to make new friendship for your user. As a result, we make a list of users, which are not directly connected to the user but have mutual friends with him. That means that these users could be friends with your user in real life, but they have not 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
10
11
var offset = 0;
var limit = 10;            
GetSocial.User.GetSuggestedFriends(offset, limit,
    friends => {
        foreach (var friend in friends) {
            Debug.Log ("Possible friend: " + friend.DisplayName + "(" + friend.MutualFriendsCount + " mutual friends)");
        }
    },
    error => {
        Debug.Log ("Exception while receiving suggested friends: " + error.Message);
    });

Give us your feedback! Was this article helpful?

😀 🙁