Skip to main content

SocialService

Provides user-facing APIs for the Social and Leaderboard Service.

TypeNameInterface Description
Functionsconstructor()

FunctionsgetFriendProfileAtIndex(index: number, onSuccess: (profile: SocialService.UserProfile | null) => void, onFailure?: (error: string) => void): void

Function: Retrieves the TikTok profile of a friend at the given 1-based index. Valid indices are 1 to the user's friend count (max 50).

Parameters

index: - The 1-based index of the friend to retrieve.

onSuccess: - Called with a UserProfile if available, or null if no friend exists at the given index.

onFailure: - Called with an error message on failure.

FunctionsgetLeaderboardInfo(index: number, type: SocialService.LeaderboardType, onSuccess: (info: SocialService.LeaderboardInfo) => void, onFailure: (error: string) => void): void

Function: Retrieves the leaderboard entry at the given 1-based index for the specified leaderboard type. Valid indices are 1 to 6. If the current user's rank is 6 or lower, index 6 will display the current user's entry. The leaderboard must have been initialized first.

Parameters

index: - The 1-based index (1–6) of the entry to retrieve.

type: - The leaderboard type (LeaderboardType).

onSuccess: - Called with a LeaderboardInfo object.

onFailure: - Called with an error message on failure, including invalid index.

FunctionsgetUserProfile(onSuccess: (profile: SocialService.UserProfile) => void, onFailure?: (error: string) => void): void

Function: Retrieves the current user's TikTok profile information. Waits for both the leaderboard system and friends list to be ready before returning the profile.

Parameters

onSuccess: - Called with the user's UserProfile when the data is ready.

onFailure: - Called with an error message if the profile cannot be retrieved.

FunctionsinitializeLeaderboard(sortBy: SocialService.LeaderboardOrder, onSuccess: (data: SocialService.LeaderboardData | null) => void, onFailure?: (error: string) => void): void

Function: Initializes the leaderboard with the specified sort order and waits for leaderboard data to arrive from the server.

Parameters

sortBy: - The ranking order (LeaderboardOrder).

onSuccess: - Called with a LeaderboardData object containing the user's best score and highest rankings, or null if no data is available.

onFailure: - Called with an error message on failure.

FunctionspostScore(): void

Function: Posts the current score to the server. The score must have been set previously via setScoreAndGetRankings.

FunctionssetScoreAndGetRankings(currScore: number): SocialService.Rankings

Function: Sets the current score and computes the user's real-time rankings across all leaderboard types. The leaderboard must have been initialized via initializeLeaderboard first.

Parameters

currScore: - The score value to set.

Returns A Rankings object with the computed friend, national, and global ranks.

Examples

constructor()

let obj = new APJS.SocialService();

getLeaderboardInfo(index: number, type: SocialService.LeaderboardType, onSuccess: (info: SocialService.LeaderboardInfo) => void, onFailure: (error: string) => void): void

social.getLeaderboardInfo(1, SocialService.LeaderboardType.Global, (info) => {
console.log(info.userName, info.score, info.ranking);
}, (error) => {
console.error(error);
});

initializeLeaderboard(sortBy: SocialService.LeaderboardOrder, onSuccess: (data: SocialService.LeaderboardData | null) => void, onFailure?: (error: string) => void): void

const social = new SocialService();
social.initializeLeaderboard(SocialService.LeaderboardOrder.HighToLow, (data) => {
if (data) {
console.log('Best score:', data.bestScore);
console.log('Friends rank:', data.highestRankings.friendsRank);
}
});

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
// TODO: instantiate / use SocialService here
}
onUpdate(deltaTime: number) {
}
}
Copyright © 2026 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalTerms of ServicePrivacy PolicyCookies