yikart/AiToEarn · error · BadRequestException
发表评论失败: ${error.response?.data?.error?.message || error.mess
Error message
发表评论失败: ${error.response?.data?.error?.message || error.message} What it means
The catch-all of postComment (tiktok.service.ts:806-809). The POST to /v2/comment/post/ failed and is re-wrapped as BadRequestException('发表评论失败: ...') with TikTok's error message. Posting comments requires the comment.list scope plus app approval, and the target video must allow comments.
Source
Thrown at project/aitoearn-electron/server/src/modules/plat/tiktok/tiktok.service.ts:808
commentDto: TikTokCommentDto
): Promise<any> {
try {
const { data } = await firstValueFrom(
this.httpService.post(`${this.apiBaseUrl}/v2/comment/post/`, {
video_id: commentDto.videoId,
text: commentDto.text
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${accessToken}`
}
})
);
return data.data;
} catch (error) {
this.logger.error('发表TikTok评论失败:', error.response?.data || error.message);
throw new BadRequestException(`发表评论失败: ${error.response?.data?.error?.message || error.message}`);
}
}
/**
* 删除评论
* @param accessToken 访问令牌
* @param videoId 视频ID
* @param commentId 评论ID
* @returns 删除结果
*/
async deleteComment(
accessToken: string,
videoId: string,
commentId: string
): Promise<any> {
try {
const { data } = await firstValueFrom(
this.httpService.post(`${this.apiBaseUrl}/v2/comment/delete/`, {View on GitHub (pinned to d3aa8bea5b)
Solutions
- Read the '发表TikTok评论失败:' log for error.response?.data.error.code/message.
- Confirm the app has been granted TikTok's comment post API access (restricted scope requiring application).
- Verify the target video has comments enabled and belongs to the authorized user.
- Sanitize/shorten the comment text and avoid duplicate/repetitive posts that trigger anti-spam.
- Refresh the access token if the error indicates auth failure.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
if (!commentDto?.videoId || !commentDto?.text?.trim()) {
throw new Error('videoId and non-empty text are required');
}
if (commentDto.text.length > 150) {
throw new Error('comment text exceeds TikTok length limit');
} Type guard
function isValidCommentDto(d: unknown): d is { videoId: string; text: string } {
const o = d as any;
return typeof o?.videoId === 'string' && o.videoId.length > 0
&& typeof o?.text === 'string' && o.text.trim().length > 0;
} Try / catch
try {
await tiktokService.postComment(token, dto);
} catch (e) {
if (/permission|not approved|scope/i.test(e.message)) {
// app lacks comment-post access: apply via TikTok developer portal
} else if (/spam|frequent/i.test(e.message)) {
// throttle: queue the comment and slow down
} else throw e;
} Prevention
- Apply early for TikTok comment-post API access — it's a restricted permission.
- Deduplicate comment text and rate-limit posts per account to avoid anti-spam.
- Check the target video allows comments before posting.
- Keep tokens fresh and re-consent when TikTok adds new required scopes.
When it happens
Trigger: POST /v2/comment/post/ returns 4xx/5xx: comment posting not approved for the app, comments disabled on the target video, text containing blocked content or exceeding length limits, invalid/expired token, or video_id not commentable.
Common situations: Apps lacking TikTok's comment API approval (it's restricted access); bots flagged by anti-spam on repeated identical comments; posting to private or comment-disabled videos; region restrictions on the comment endpoints.
Related errors
- 获取评论失败: ${error.response?.data?.error?.message || error.mess
- 删除评论失败: ${error.response?.data?.error?.message || error.mess
- 初始化视频上传失败: ${error.response?.data?.error?.message || error.m
- 视频上传发布失败: ${error.response?.data?.error?.message || error.me
- 发布视频失败: ${error.response?.data?.error?.message || error.mess
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/cc9c114ba458d465.
Report an issue: GitHub.