Social Graph
Define relationships between users and use them to personalize their experience
Social Graph is an API-first service that enables products to define and explore the social connections between their users and then use those relationships to personalize features. As a product developer using the Social Graph service, you will be able to:
- Create and query connections between your users
- Define your own relationship types like followers, friends, classmates, or anything else
- Discover and analyze connections in your network of users
- Integrate with your existing features and user data
Social Graph Basics
The Social Graph system can be thought of a graph where the nodes are Profiles and the edges are the relationships between profiles.
- A Profile Relationship represents a connection between two profiles. Each relationship consists of a from profile, a to profile, and a relationship type. A profile relationship is essentially a directed edge of the given type from one profile to another. Two profiles can share more than one relationship as long as the type is unique between them.
- A Relationship Type represents a kind of possible relationship between profiles. Each type has a unique key that is used when creating relationships between profiles. A common relationship type is "follows" but you can define your own types like "studies with" or "rival of."
Working with the Social Graph Service
All social graph functions are available via a single client interface per platform.
socialGraphClient = (application as LiveLikeApplication).sdk.socialGraphClient()
let sdk: EngagementSDK
sdk.socialGraphClient
import LiveLike from "@livelike/engagementsdk";
All relations between profiles must fall into a predefined relationship type. New relationship types can be created via the Create a Relationship Type endpoint, and existing ones can be queried via the client interface.
socialGraphClient.getProfileRelationshipTypes(
LiveLikePagination.FIRST,
object : LiveLikeCallback<List<ProfileRelationshipType>>(){
override fun onResponse(result: List<ProfileRelationshipType>?, error: String?) {
...
}
}
)
let sdk: EngagementSDK
sdk.socialGraphClient.getProfileRelationshipTypes(
page: .first,
options: nil
) { result in
switch result {
case .failure(let error):
// handle error
case .success(let relationshipTypes):
// handle success
}
}
LiveLike.getProfileRelationshipTypes().then(({results}) => console.log(results))
Querying relationships
Using the client you can query relationships by any combination of the three parameters to profile
, relationship type
and from profile
This is an example to find who is following me
socialGraphClient.getProfileRelationships(
GetProfileRelationshipsRequestParams(
relationshipTypeKey = "follow",
toProfileId = "my profile id",
),
LiveLikePagination.FIRST,
object : LiveLikeCallback<List<ProfileRelationship>>() {
override fun onResponse(
result: List<ProfileRelationship>?,
error: String?
) {
...
}
}
)
let sdk: EngagementSDK
let requestOptions = GetProfileRelationshipsOptions(
relationshipTypeKey: "follow",
fromProfileID: nil,
toProfileID: "my profile ID"
)
sdk.socialGraphClient.getProfileRelationships(
page: .first,
options: requestOptions
) { result in
switch result {
case .failure(let error):
// handle error
case .success(let relationshipTypes):
// handle success
}
}
LiveLike.getProfileRelationships({
relationshipTypeKey: "follow",
toProfileId: "<Profile ID>",
}).then(({results}) => console.log(results))
This example is who am I following
socialGraphClient.getProfileRelationships(
GetProfileRelationshipsRequestParams(
fromProfileId = "my profile id",
relationshipTypeKey = "follow",
),
LiveLikePagination.FIRST,
object : LiveLikeCallback<List<ProfileRelationship>>() {
override fun onResponse(
result: List<ProfileRelationship>?,
error: String?
) {
...
}
}
)
let sdk: EngagementSDK
let requestOptions = GetProfileRelationshipsOptions(
relationshipTypeKey: "follow",
fromProfileID: "my profile ID",
toProfileID: nil
)
sdk.socialGraphClient.getProfileRelationships(
page: .first,
options: requestOptions
) { result in
switch result {
case .failure(let error):
// handle error
case .success(let relationshipTypes):
// handle success
}
}
LiveLike.getProfileRelationships({
relationshipTypeKey: "follow",
fromProfileId: "<Profile ID>",
}).then(({results}) => console.log(results))
Managing relationships
Creating relationships is done one at a time via the client interface
socialGraphClient.createProfileRelationship(
CreateProfileRelationshipRequestParams(
fromProfileId = "my profile id",
relationshipTypeKey = "follow",
toProfileId = "profile id i'm following",
),
object : LiveLikeCallback<ProfileRelationship> (){
override fun onResponse(result: ProfileRelationship?, error: String?) {
...
}
}
)
let sdk: EngagementSDK
let requestOptions = CreateProfileRelationshipOptions(
fromProfileID: "source profile ID",
toProfileID: "target profile ID",
relationshipTypeKey: "follow"
)
sdk.socialGraphClient.createProfileRelationship(
options: requestOptions
) { result in
switch result {
case .failure(let error):
// handle error
case .success(let relationshipTypes):
// handle success
}
}
LiveLike.createProfileRelationship({
relationshipTypeKey: "follow",
toProfileId: "<Profile ID>",
fromProfileId: "<Profile ID>",
}).then((profileRelationship) => console.log(profileRelationship))
Create your relationship types before creating relationships
A relationship type key must exist before it can be used to define relationships between profiles. Use the Create a Relationship Type endpoint to create one.
Deleting relationships is similarly achieved via the client interface
socialGraphClient.deleteProfileRelationship(
DeleteProfileRelationshipsRequestParams( "id of relationship" ),
object : LiveLikeCallback<LiveLikeEmptyResponse> (){
override fun onResponse(result: LiveLikeEmptyResponse?, error: String?) {
...
}
}
)
let sdk: EngagementSDK
let requestOptions = DeleteProfileRelationshipOptions(
profileRelationshipID: "profile relationship ID to delete"
)
sdk.socialGraphClient.deleteProfileRelationship(
options: requestOptions
) { result in
switch result {
case .failure(let error):
// handle error
case .success(let relationshipTypes):
// handle success
}
}
LiveLike.deleteProfileRelationship({ relationshipId: "<Profile Relationship ID>" })
Updated 10 months ago