SocialService
Provides user-facing APIs for the Social and Leaderboard Service.
| Type | Name | Interface Description |
|---|---|---|
| Functions | constructor() | |
| Functions | getFriendProfileAtIndex(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 • • • |
| Functions | getLeaderboardInfo(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 • • • • |
| Functions | getUserProfile(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 • • |
| Functions | initializeLeaderboard(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 • • • |
| Functions | postScore(): void | • Function: Posts the current score to the server. The score must have been set previously via setScoreAndGetRankings. |
| Functions | setScoreAndGetRankings(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 • 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) {
}
}