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.text

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Check the '获取TikTok视频评论失败:' log for TikTok's error code (e.g. access token invalid, permission denied).
  2. Ensure the OAuth flow requested comment.list (and comment.list.generate for replies) and re-authenticate.
  3. Verify video_id belongs to the token's user; comments on others' videos are not listable via this API.
  4. Reset pagination to omit cursor on the first call and always use fresh cursors from the previous response.
  5. 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

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


AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31). Data as JSON: /api/errors/a4d877a6d90da3b1. Report an issue: GitHub.