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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
List<String> getSocialUserIds = Arrays.asList("user_id_1", "user_id_2");

GetSocial.User.setFriends(getSocialUserIds, new CompletionCallback() {
    @Override
    public void onSuccess() {
        Log.i("GetSocial","Friends data successfuly imported.");
    }

    @Override
    public void onFailure(GetSocialException exception) {
        Log.e("GetSocial", "Exception while importing friends: " + exception.getMessage());
    }
});

By Auth Identities

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
List<String> providerUserIds = Arrays.asList("external_user_id_1", "external_user_id_2");
String identityProviderId = "my_custom_identity_provider_id";

GetSocial.User.setFriendsByAuthIdentities(identityProviderId, providerUserIds, new CompletionCallback() {
    @Override
    public void onSuccess() {
        Log.i("GetSocial","Friends data successfuly imported.");
    }

    @Override
    public void onFailure(GetSocialException exception) {
        Log.e("GetSocial", "Exception while importing friends: " + exception.getMessage());
    }
});

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
10
11
12
13
final String getSocialUserId = anotherUser.getId();

GetSocial.User.addFriend(getSocialUserId, new Callback<Integer>() {
    @Override
    public void onSuccess(Integer friendsCount) {
        Log.i("GetSocial", getSocialUserId + " successfully added as a friend. Total friends count: " + friendsCount);
    }

    @Override
    public void onFailure(GetSocialException exception) {
        Log.e("GetSocial", "Exception while adding a friend: " + exception.getMessage());
    }
});

By Auth Identities

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
List<String> providerUserIds = Arrays.asList("external_user_id_1", "external_user_id_2");
String identityProviderId = "my_custom_identity_provider_id";

GetSocial.User.addFriendsByAuthIdentities(identityProviderId, providerUserIds, new Callback<Integer>() {
    @Override
    public void onSuccess(Integer friendsCount) {
        Log.i("GetSocial", "Friends successfully added. Total friends count: " + friendsCount);
    }

    @Override
    public void onFailure(GetSocialException exception) {
        Log.e("GetSocial", "Exception while adding friends: " + exception.getMessage());
    }
});

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 on 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
10
11
12
13
final String getSocialUserId = anotherUser.getId();

GetSocial.User.removeFriend(getSocialUserId, new Callback<Integer>() {
    @Override
    public void onSuccess(Integer friendsCount) {
        Log.i("GetSocial", getSocialUserId + " successfully removed from a friends list. Total friend count: " + friendsCount);
    }

    @Override
    public void onFailure(GetSocialException exception) {
        Log.e("GetSocial", "Exception while removing a friend: " + exception.getMessage());
    }
});

By Auth Identities

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
List<String> providerUserIds = Arrays.asList("external_user_id_1", "external_user_id_2");
String identityProviderId = "my_custom_identity_provider_id";

GetSocial.User.removeFriendsByAuthIdentities(identityProviderId, providerUserIds, new Callback<Integer>() {
    @Override
    public void onSuccess(Integer friendsCount) {
        Log.i("GetSocial", "Users successfully removed from a friends list. Total friend count: " + friendsCount);
    }

    @Override
    public void onFailure(GetSocialException exception) {
        Log.e("GetSocial", "Exception while removing friends: " + exception.getMessage());
    }
});

Give us your feedback! Was this article helpful?

😀 🙁