下载
使用 POST 请求下载所请求的数据。响应将以 HTTP 数据 ZIP 文件的形式进行流式传输。
HTTP URL | https://open.tiktokapis.com/v2/user/data/download/ |
HTTP 方法 | POST |
Scopes | portability.all.single, portability.all.ongoing, portability.activity.single, portability.activity.ongoing, portability.directmessages.single, portability.directmessages.ongoing, portability.postsandprofile.single, portability.postsandprofile.ongoing, |
Request
Headers
Key | Type | 描述 | 示例 | 必需 |
Authorization | string | 承载对 TikTok 用户授权的令牌,该令牌通过 /v2/oauth/token/ 获取 | Bearer clt.example12345Example12345Example | 是 |
Content-Type | string | 资源的原始媒体类型 | application/json | 是 |
Body
Key | Type | 描述 | 示例 | 必需 |
request_id | int64 | 用于跟踪下载数据请求的唯一 ID。该值可从 Add Data Request API 获取。 | 123123123123 | 是 |
响应
响应将以 HTTP zip 文件形式进行流式传输,且必须转换为 zip 文件以获取正确的数据。
此 Python 脚本可用于发送 POST 请求,并以可读格式获取成功响应中的数据
import requests
import json
url = "https://open.tiktokapis.com/v2/user/data/download/"
# The request_id returned from the `Add Data Request` API
request_id = <REQUEST ID>
# Request JSON structure
payload = json.dumps({
"request_id": request_id
})
# Necessary headers
# Authorization must have the token obtained from the /v2/oauth/token/ API
headers = {
'Content-Type': 'application/json',
'Authorization': 'AUTHORIZATION_TOKEN'
}
response = requests.request("POST", url, headers=headers, data=payload)
zip_file_path = f'./{request_id}.zip'
# Open the zip file in write-binary mode
with open(zip_file_path, 'wb') as zip_file:
# Write the content of the response to the zip file
zip_file.write(response.content)成功示例
.zip必须将其添加到流式传输的数据中,才能使其成为 zip 文件。数据本身在以 unicode 查看时不会对人类可读。
失败示例
如果下载请求不成功,将返回以下响应
{
"data": {},
"error": {
"code": "invalid_params",
"http_status_code": 400,
"log_id": "20240125230933D4C4606E87F0A61BE502",
"message": "Incorrect `request_id`. Please validate the request."
}
}