Fetching Followers¶
Now, let's dive into the data you can retreive around followers on TikTok.
User Followers API¶
Our TikTok Followers API allows you to retrieve a user's most recent 5000 followers, i.e the last 5000 people to follow this user. To do so we'll require both the the user id and the secondary user id.
result = requests.get(
"https://ensembledata.com/apis/tt/user/followers",
params={
"id": "6784819479778378757",
"secUid": "MS4wLjABAAAAQ45IcDZIqrknyl0FDjs7xDlcxlaRE7CcBx1ENxYkWK00UpeKTTlCQWKxq6t9QM6b",
"token": "API_TOKEN",
}
).json()["data"]
followers = result["followers"]
follower_count = result["total"]
next_cursor = result["nextCursor"]
A single request will return 100 followers. To get more, send another request, this time passing in the cursor value we got from the previous request (What is a cursor?). Note: the maximum you can retrieve is 5000.
User Followings API¶
Additionally, you can fetch the 'followings', which are the people the user themself follows. This endpoint works very similarly to the endpoint to fetch followers:
result = requests.get(
"https://ensembledata.com/apis/tt/user/followings",
params={
"id": "6784819479778378757",
"secUid": "MS4wLjABAAAAQ45IcDZIqrknyl0FDjs7xDlcxlaRE7CcBx1ENxYkWK00UpeKTTlCQWKxq6t9QM6b",
"token": "API_TOKEN",
}
).json()["data"]
followers = result["followings"]
follower_count = result["total"]
next_cursor = result["nextCursor"]
next_page_token = result["nextPageToken"]
A single request will return 100 followings. To get more you'll need to use the cursor
AND the page_token
. Let's see how we can get the next chunk of followings below:
result = requests.get(
"https://ensembledata.com/apis/tt/user/followings",
params={
"id": "6784819479778378757",
"secUid": "MS4wLjABAAAAQ45IcDZIqrknyl0FDjs7xDlcxlaRE7CcBx1ENxYkWK00UpeKTTlCQWKxq6t9QM6b",
"cursor": next_cursor,
"page_token": next_page_token,
"token": "API_TOKEN",
}
).json()["data"]
next_cursor = result["nextCursor"]
next_page_token = result["nextPageToken"]
Easy! We successfully used the cursor to get more results. You can continue this process until there is no nextCursor
or nextPageToken
in the response, which indicates that there are no more retrievable results.