yikart/AiToEarn · error · BadRequestException
accountId和视频大小是必须的
Error message
accountId和视频大小是必须的
What it means
initVideoPublish performs TikTok's publish-init handshake, which requires the target accountId (to resolve the access token) and videoSize in bytes (TikTok's chunked upload API needs the total size up front). Either missing triggers this 400 BadRequestException.
Source
Thrown at project/aitoearn-electron/server/src/modules/plat/tiktok/tiktok.controller.ts:436
}
})
async initVideoPublish(
@GetToken() systemToken: TokenInfo,
@Body('accountId') accountId: string,
@Body('videoSize') videoSize: number,
@Body() videoInfo: {
title?: string;
description?: string;
privacyLevel?: string;
disableComment?: boolean;
disableDuet?: boolean;
disableStitch?: boolean;
videoCoverTimestampMs?: number;
hashtags?: string[];
}
) {
if (!accountId || !videoSize) {
throw new BadRequestException('accountId和视频大小是必须的');
}
const accessToken = await this.tikTokAuthService.getUserAccessToken(accountId);
return this.tikTokService.initVideoPublish(accessToken, videoSize, videoInfo);
}
/**
* 检查视频发布状态(新版API)
*/
@Post('videos/publish/status')
@ApiOperation({ summary: '检查视频发布状态' })
@ApiBody({
schema: {
type: 'object',
properties: {
accountId: { type: 'string', description: 'TikTok账号ID' },
publishId: { type: 'string', description: '发布ID' }
},View on GitHub (pinned to d3aa8bea5b)
Solutions
- Compute the video file size in bytes and include it as videoSize in the body.
- Include the accountId of the connected TikTok account.
- On the client, stat/read the file metadata before calling initVideoPublish.
Example fix
// before
await api.post('/tiktok/video/publish/init', { accountId });
// after
const videoSize = fs.statSync(filePath).size;
await api.post('/tiktok/video/publish/init', { accountId, videoSize }); Defensive patterns
Strategy: validation
Validate before calling
const videoSize = typeof file === 'object' ? file.size : require('fs').statSync(videoPath).size;
if (!accountId || !Number.isFinite(videoSize) || videoSize <= 0) {
throw new Error('accountId and a positive videoSize (bytes) are required');
} Type guard
function isInitPayload(p: { accountId?: string; videoSize?: number }): p is { accountId: string; videoSize: number } {
return typeof p.accountId === 'string' && p.accountId !== '' &&
typeof p.videoSize === 'number' && Number.isFinite(p.videoSize) && p.videoSize > 0;
} Try / catch
try {
await api.post('/tiktok/video/publish/init', { accountId, videoSize });
} catch (e) {
if (e.response?.status === 400) {
console.error('initVideoPublish requires accountId and videoSize:', e.response.data?.message);
}
} Prevention
- Always stat/read the file before initiating a chunked upload.
- Reject zero-byte files early in the client pipeline.
- Keep accountId in a shared upload-context object used by all publish steps.
When it happens
Trigger: Calling the init-publish endpoint with an accountId but no videoSize, or neither — e.g. a file whose size could not be read, or a body constructed before the file was stat'd.
Common situations: Streaming uploads where the file size is unknown; forgetting to fs.stat the file before initializing; publishing flows that assume the server reads the file itself.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- accountId, videoId和commentId是必须的
- videoId, userId和accountId是必须的
- accountId和publishId是必须的
- No subtitle entries in response
- Invalid public upload id
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/30487e749c5034f2.
Report an issue: GitHub.