Music¶
Music is another very important part of the TikTok ecosystem. The EnsembleData API has several endpoints that allow you to interact with music data. Let's start by looking at how we can find music using a keyword.
Music Search API¶
Aside from supplying a keyword, you'll need to specify how you want the results to be filtered and sorted. Let's take a look at the options:
Sorting¶
0
: sort byrelevance
(best keyword match, according to TikTok)1
: sort bymost used
music2
: sort bymost recent
music3
: sort byshortest
music4
: sort bylongest
music
Filtering¶
0
: No filter applied1
: only search music2
: only search music creators
import requests
result = requests.get(
"https://ensembledata.com/apis/tt/music/info",
params={
"name": "classical",
"sorting": "0",
"filter_by": "0",
"cursor": 0,
"token": "API_TOKEN",
}
).json()["data"]
music = result["music"]
next_cursor = result.get("nextCursor", None)
# Show the first music result
print("Title:", music[0]["title"])
print("Author:", music[0]["author"])
print("Music ID:", music[0]["mid"])
from ensembledata.api import EDClient
client = EDClient("API_TOKEN")
result = client.tiktok.music_search(
keyword="classical",
sorting="0",
filter_by="0",
)
music = result.data["music"]
next_cursor = result.data.get("nextCursor")
# Show the first music result
print("Title:", music[0]["title"])
print("Author:", music[0]["author"])
print("Music ID:", music[0]["mid"])
import { EDClient } from "ensembledata";
const client = new EDClient({ token: "API_TOKEN" });
let result = await client.tiktok.music_search({
keyword: "classical",
sorting: "0",
filter_by: "0",
});
const music = result.data.music;
const nextCursor = result.data.nextCursor;
// Show the first music result
console.log("Title:", music[0].title);
console.log("Author:", music[0].author);
console.log("Music ID:", music[0].mid);
Fetch more results¶
To search for more music, simply add the cursor
parameter to the request, using the nextCursor
value you got from the previous request.
Music Posts API¶
Once you've got your hands on a music ID, you can use it to fetch posts that use that music.
Fetching more posts¶
To fetch more posts, use the cursor
parameter.
Music Details API¶
If you've got a music ID and want to get more information about it, you can use the Music Details
endpoint.
In the response payload you can find links to the music itself, artist/author information, duration etc. We recommend perusing the response payload to see what else you can get from this endpoint.