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 getVideoComments (tiktok.service.ts:776-779). The GET to /v2/comment/list/ failed, and the Axios error is re-wrapped as BadRequestException('获取评论失败: ...') with TikTok's error message when present. This service surface requires the comment.list scope and the video must belong to the token's user.
Source
Thrown at project/aitoearn-electron/server/src/modules/plat/tiktok/tiktok.service.ts:778
};
if (cursor) {
params.cursor = cursor;
}
const { data } = await firstValueFrom(
this.httpService.get(`${this.apiBaseUrl}/v2/comment/list/`, {
params,
headers: {
'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 commentDto 评论参数
* @returns 评论结果
*/
async postComment(
accessToken: string,
commentDto: TikTokCommentDto
): Promise<any> {
try {
const { data } = await firstValueFrom(
this.httpService.post(`${this.apiBaseUrl}/v2/comment/post/`, {
video_id: commentDto.videoId,
text: commentDto.textView on GitHub (pinned to d3aa8bea5b)
Solutions
- Check the '获取TikTok视频评论失败:' log for TikTok's error code (e.g. access token invalid, permission denied).
- Ensure the OAuth flow requested comment.list (and comment.list.generate for replies) and re-authenticate.
- Verify video_id belongs to the token's user; comments on others' videos are not listable via this API.
- Reset pagination to omit cursor on the first call and always use fresh cursors from the previous response.
- For 429, back off — the comment list endpoint is rate-limited.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
// Ensure scope before calling; TikTok exposes no scope-check endpoint per user,
// so gate at token storage time:
const required = ['comment.list'];
const granted = storedToken.scopes ?? [];
if (!required.every(s => granted.includes(s))) {
throw new Error(`missing scopes: ${required.filter(s => !granted.includes(s)).join(',')}`);
} Type guard
function isCommentListPayload(d: unknown): d is { comments?: unknown[]; has_more?: boolean; cursor?: string } {
const o = d as any;
return o === null || typeof o === 'object';
} Try / catch
try {
const comments = await tiktokService.getVideoComments(token, videoId);
} catch (e) {
if (/permission|scope|access_token/i.test(e.message)) {
// trigger OAuth re-consent with comment.list included
} else if ((e as any).response?.status === 429) {
await backoffAndRetry(() => tiktokService.getVideoComments(token, videoId));
} else throw e;
} Prevention
- Request comment.list scope during OAuth and store the granted scope list.
- Only list comments for videos owned by the token's user.
- Always pass fresh cursors from the previous response, never stale ones.
- Respect rate limits: keep max_count within 1-50 and space out calls.
When it happens
Trigger: GET /v2/comment/list/ returns 4xx/5xx: missing comment.list scope, video_id not owned by the user, invalid cursor from a stale pagination, invalid max_count outside 1-50, or expired token / network failure.
Common situations: App approved without comment read scopes; comment APIs unavailable in the app's region or for the video's privacy setting; stale cursors after comments were deleted; calling for videos published by other users.
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/a4d877a6d90da3b1.
Report an issue: GitHub.