1.0.94 • Published 4 years ago

ttdownapi v1.0.94

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

TikTok API

This is an unofficial Node.js implementation of the TikTok API. This module is not endorsed by, directly affiliated with, maintained, authorized, or sponsored by TikTok. Their internal API could change at any moment, and break this module's code. I try my best to maintain it, and keep it up-to-date. If you find bugs or have any questions, please submit an issue, and I will try my best to help you out.

Table of Contents

Quick Examples

Get the follower count of a TikTok user:

const tiktok = require('tiktok-app-api');

const user = await tiktok.getUserByName('example');
const userInfo = await tiktok.getUserInfo(user);

console.log(userInfo.followerCount);

Get the tags of the top trending video:

const tiktok = require('tiktok-app-api');

const trendingVideos = await tiktok.getTrendingVideos();

console.log(trendingVideos[0].tags);

Installation

You must install puppeteer in order to run the API. Although, take a look at TikTok-Web-API to run this module as a web service.

Install the api:

npm i tiktok-app-api

Import into your program.

const tiktok = require('tiktok-app-api');

// Or, if you are using TypeScript:
import tiktok = require('tiktok-app-api'):

Usage

At the moment, the majority of the API returns promises, and may throw errors in certain situations. When a promise is not returned, or if a function may throw an error, it will be mentioned.

Trending

To get the top trending videos using the API is as simple as:

const trendingVideos = await tiktok.getTrendingVideos();

console.log(trendingVideos);

Users

To retrieve User information within the API, you will first need to get a User object. See User for a definition of the User object.

Get a User object from a TikTok user's username:

Will fetch ID of user from TikTok API. May throw an error in certain situations, see here.

const user = await tiktok.getUserByName('example');

Get a User object from a TikTok user's id:

Will not fetch username of user from TikTok API.

const user = tiktok.getUserByID('6828402025898902533');

Take note that getUserByID(id) does not return a promise, as it does not fetch any information from the TikTok API.

Now that we have a User object, we can retrieve some information from the TikTok user:

See UserInfo for a defintion of the UserInfo object. May throw an error in certain situations, see here.

const userInfo = await tiktok.getUserInfo(user);

console.log(userInfo.followingCount, userInfo.followerCount, userInfo.likeCount);

Now, let's get the user's lastest videos:

See VideoInfo for a definition of the VideoInfo object. May throw an error in certain situations, see here.

const recentVideos = await tiktok.getRecentVideos(user);

console.log(recentVideos[0].description, recentVideos[0].playCount, recentVideos[0].tags);

Same idea, we can get the user's liked videos:

May throw an error in certain situations, see here.

const likedVideos = await tiktok.getLikedVideos(user);

console.log(likedVideos[0].audio, likedVideos[0].shareCount, likedVideos[0].likeCount);

That covers users. Let's move on to TikTok videos.

Videos

Just like how previously we needed our User object, we now need our Video object. See Video for a definition of the Video object.

const video = tiktok.getVideo('6829280471411674374');

Take note that getVideo(id) does not return a promise, as it does not fetch any information from the TikTok API.

Now to get the information of this video:

May throw an error in certain situations, see here.

const videoInfo = await tiktok.getVideoInfo(video);

console.log(videoInfo.commentCount, videoInfo.author, videoInfo.video.id);

That's all there is for videos, for now. Now on to Tiktok audios.

Audios

Just like Users and Videos, we first need an Audio object.

const audio = tiktok.getAudio('6829280451471969029');

Take note that getAudio(id) does not return a promise, as it does not fetch any information from the TikTok API.

To get the information related to the audio:

See AudioInfo for a definition of the AudioInfo object. May throw an error in certain situations, see here.

const audioInfo = await tiktok.getAudioInfo(audio);

console.log(audioInfo.title, audioInfo.audio.title);

To get the top videos related to an audio:

The first object of this VideoInfo array will be the original video with the audio. May throw an error in certain situations, see here.

const topVideos = await tiktok.getAudioTopVideos(audio);

console.log(topVideos[0]);

Finally we have TikTok tags.

Tags

Just like Users, Videos, and Audios, we need a Tag object.

Will fetch the title from the TikTok API, therefore this function returns a promise. May throw an error in certain situations, see here.

const tag = await tiktok.getTag('fyp');

To retrieve the information associated with the tag:

See TagInfo for a definition of the TagInfo object. May throw an error in certain situations, see here.

const tagInfo = await tiktok.getTagInfo(tag);

console.log(tagInfo.description, tagInfo.videoCount, tagInfo.viewCount);

To get the top videos of a tag:

May throw an error in certain situations, see here.

const topVideos = await tiktok.getTagTopVideos(tag);

console.log(topVideos);

Object Reference

Below you will find the data that each object contains.

User

User {
  id: string,
  username?: string // Not required initially.
}

UserInfo

UserInfo {
  user: User,
  avatar: string,
  nickname: string,
  signature: string,
  followingCount: number,
  followerCount: number,
  likeCount: number,
  videoCount: number
}

Video

Video {
  id: string
}

VideoInfo

VideoInfo {
  video: Video,
  author: User,
  playCount: number,
  likeCount: number,
  commentCount: number,
  shareCount: number,
  description: string,
  tags: Tag[],
  audio: AudioInfo
}

Audio

Audio {
  id: string
}

AudioInfo

AudioInfo {
  id: string,
  title: string
}

Tag

Tag {
  id: string,
  title: string
}

TagInfo

TagInfo {
  tag: Tag,
  description: string,
  videoCount: number,
  viewCount: number
}
1.0.94

4 years ago

1.0.93

4 years ago

1.0.92

4 years ago

1.0.91

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago