我正在尝试使用此端点将视频上传到 Tiktok:
https://open-api.tiktok.com/share/video/upload/ https://open-api.tiktok.com/share/video/upload/
按照官方文档:https://developers.tiktok.com/doc/web-video-kit-with-web https://developers.tiktok.com/doc/web-video-kit-with-web
(成功通过 Tiktok 进行身份验证并使用 Login Kit API 获取访问令牌后)。
我收到一条表明成功的响应(error_code=0 且 share_id 非空),但是没有上传任何内容,并且我的 Tiktok 应用程序的回调 URL 似乎没有被任何状态更新触发。
我尝试过从几个不同的环境访问 API - Node.js 运行时(使用 Axios)、来自 2 台不同机器的 cURL 请求(都得到上述结果)以及使用 Fetch 从我的前端代码(这个让我CORS 错误)。下面的代码片段。
我将不胜感激任何帮助,因为我不知道接下来要尝试什么。此外,如果除了我链接的文档或在线资源之外还有任何其他文档或在线资源可能会有所帮助,那么任何此类链接都会很棒。
注意:我确保我的测试视频满足文档中提到的限制。
我的 Node.js 代码:
const url = `https://open-api.tiktok.com/share/video/upload?open_id=${openId}&access_token=${accessToken}`;
const data = new FormData();
data.append('video', fs.createReadStream(path.join(os.tmpdir(), 'test.mp4')));
await axios.post(url, data, {
headers: data.getHeaders()
});
卷曲请求:
curl --location --request POST 'https://open-api.tiktok.com/share/video/upload?open_id=<open_id>&access_token=<access_token>' --form 'video=@"/path/to/video.mp4"'
响应负载(对于 cURL 和 Node.JS 请求):
{"data":{"err_code":0,"error_code":0,"share_id":"video.7031619168818448385.CGdXCmaC"},"extra":{"error_detail":"","logid":"2021111721133201024513311411A971D3"}}
前端代码(获取,在 Location 标头中使用相同的 Tiktok URL(/share/video/upload...)获取 307 响应 - 导致 CORS 错误):
const formData = new FormData();
formData.append('video', selectedFile);
const requestOptions = {
method: 'POST',
body: formData,
redirect: 'follow'
};
const URL = `https://open-api.tiktok.com/share/video/upload?access_token=${accessToken}&open_id=${openId}`;
fetch(URL, requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log('error', error));