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 setFriendsWith... 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
NSArray* getSocialUserIds = @[@"1234", @"4567"];
[GetSocialUser setFriendsWithIds:getSocialUserIds success:^() {
    NSLog(@"Friends successfully replaced.");
} failure:^(NSError *error) {
    NSLog(@"Exception while replacing a friends: %@", error);
}];

By Auth Identities

You can also replace existing friends by their identities.

1
2
3
4
5
6
7
NSArray* providerUserIds = @[@"1234", "456"];
NSString* identityProviderId = @"custom_auth_method";
[GetSocialUser setFriendsWithIds:providerUserIds forProvider:identityProviderId success:^(void) {
    NSLog(@"Friends successfully replaced.");
} failure:^(NSError *error) {
    NSLog(@"Exception while replacing friends: %@", error);
}];

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
NSString *getSocialUserId = anotherUser.userId;
[GetSocialUser addFriend:getSocialUserId success:^(int friendsCount) {
    NSLog(@"%@ successfully added as a friend. Total friend count: %d", getSocialUserId, friendsCount);
} failure:^(NSError *error) {
    NSLog(@"Exception while adding a friend: %@", error);
}];

By Auth Identities

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

1
2
3
4
5
6
7
NSArray* providerUserIds = @[@"1234", @"456"];
NSString* identityProviderId = @"custom_auth_method";
[GetSocialUser addFriendsWithIds:providerUserIds forProvider:identityProviderId success:^(int friendsCount) {
    NSLog(@"Friends successfully added. Total friend count: %d" , friendsCount);
} failure:^(NSError *error) {
    NSLog(@"Exception while adding a friends: %@", error);
}];

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
NSString *getSocialUserId = anotherUser.userId;
[GetSocialUser removeFriend:getSocialUserId success:^(int friendsCount) {
    NSLog(@"%@ successfully removed from friends. Total friends count: %d", getSocialUserId, friendsCount);
} failure:^(NSError *error) {
    NSLog(@"Exception while removing a friend: %@", error);
}];

By Auth Identities

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

1
2
3
4
5
6
7
NSArray* providerUserIds = @[@"1234", "456"];
NSString* identityProviderId = @"custom_auth_method";
[GetSocialUser removeFriendsWithIds:providerUserIds forProvider:identityProviderId success:^(int friendsCount) {
    NSLog(@"Friends successfully removed. Total friends count: %d", friendsCount);
} failure:^(NSError *error) {
    NSLog(@"Exception while removing friends: %@", error);
}];

Give us your feedback! Was this article helpful?

😀 🙁