Skip to content

Building Social Graph Relationships

Prerequisite

Overview

GetSocial SDK exposes all the methods needed to import existing connections between users or gradually add/remove connections in the graph. All methods can operate on GetSocial user IDs or user IDs from external identities like Facebook, or your identity provider.

Importing Friends

If your app already has a concept of friends or any kind of the relationship between users you can import this data into GetSocial Social Graph to leverage friend suggestions or advanced segmentation in Smart Audiences.

Important to know that import with setFriends(...) methods will overwrite existing connections. You have to ensure you call it only once.

By GetSocial User IDs

You can replace existing friends with the provided list of users.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
List<string> getSocialUserIds = new List<string>();
getSocialUserIds.Add("123");
getSocialUserIds.Add("456");

GetSocial.User.SetFriends(getSocialUserIds,
    () => {
        Debug.Log ("Successfully replaced friends. ");
    },
    error => {
        Debug.Log ("Exception while replacing friend: " + error.Message);
    });

By Auth Identities

You can also replace existing friends by their identities.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
List<string> providerUserIds = new List<string>();
providerUserIds.Add("123");
providerUserIds.Add("456");
string identityProviderId = "custom_auth_method";

GetSocial.User.SetFriends(identityProviderId, providerUserIds,
    () => {
        Debug.Log ("Successfully replaced friends. ");
    },
    error => {
        Debug.Log ("Exception while replacing friend: " + error.Message);
    });

Adding a Friend

You can make any user become a friend of the current user. If the operation succeeds, both of them will be friends. If you are trying to add a user, that is your friend already, the operation will succeed, nothing will be changed, and you will just receive the current friends count.

By GetSocial User IDs

1
2
3
4
5
6
7
8
9
var getSocialUserId = anotherUser.Id;

GetSocial.User.AddFriend (getSocialUserId,
    friendsCount => {
        Debug.Log (getSocialUserId + " successfully added as a friend. Total friends count: " + friendsCount);
    },
    error => {
        Debug.Log ("Exception while adding a friend: " + error.Message);
    });

By Auth Identities

You can also add one or multiple friends by their identities.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
List<string> providerUserIds = new List<string>();
providerUserIds.Add("123");
providerUserIds.Add("456");
string identityProviderId = "custom_auth_method";

GetSocial.User.AddFriendsByAuthIdentities(identityProviderId, providerUserIds,
    friendsCount => {
        Debug.Log ("Successfully added friends. Total friends count: " + friendsCount);
    },
    error => {
        Debug.Log ("Exception while adding friend: " + error.Message);
    });

Removing a Friend

You can remove any user from the current user’s friend list by user’s unique ID. If you are trying to remove a user, who’s not in the friend list, the operation will succeed, nothing will be changed, and you will just receive the current friends count.

By GetSocial User IDs

1
2
3
4
5
6
7
8
9
var getSocialUserId = anotherUser.Id;

GetSocial.User.RemoveFriend (getSocialUserId,
    friendsCount => {
        Debug.Log (getSocialUserId + " successfully removed from friends. Total friends count: " + friendsCount);
    },
    error => {
        Debug.Log ("Exception while removing a friend: " + error.Message);
    });

By Auth Identities

You can also remove one or multiple friends by their identities.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
List<String> providerUserIds = new ArrayList<String>();
userIdList.Add("123");
userIdList.Add("456");
string identityProviderId = "custom_auth_method";

GetSocial.User.RemoveFriendsByAuthIdentities(identityProviderId, providerUserIds
    friendsCount => {
        Debug.Log ("Successfully removed friends. Total friends count: " + friendsCount);
    },
    error => {
        Debug.Log ("Exception while removing a friend: " + error.Message);
});

Give us your feedback! Was this article helpful?

😀 🙁