{"record":{"id":"cc9c114ba458d465","repo":"yikart/AiToEarn","slug":"error-response-data-error-message-cc9c11","errorCode":null,"errorMessage":"发表评论失败: ${error.response?.data?.error?.message || error.message}","messagePattern":"发表评论失败: (.+?)","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"project/aitoearn-electron/server/src/modules/plat/tiktok/tiktok.service.ts","lineNumber":808,"sourceCode":"    commentDto: TikTokCommentDto\n  ): Promise<any> {\n    try {\n      const { data } = await firstValueFrom(\n        this.httpService.post(`${this.apiBaseUrl}/v2/comment/post/`, {\n          video_id: commentDto.videoId,\n          text: commentDto.text\n        }, {\n          headers: {\n            'Content-Type': 'application/json',\n            'Authorization': `Bearer ${accessToken}`\n          }\n        })\n      );\n\n      return data.data;\n    } catch (error) {\n      this.logger.error('发表TikTok评论失败:', error.response?.data || error.message);\n      throw new BadRequestException(`发表评论失败: ${error.response?.data?.error?.message || error.message}`);\n    }\n  }\n\n  /**\n   * 删除评论\n   * @param accessToken 访问令牌\n   * @param videoId 视频ID\n   * @param commentId 评论ID\n   * @returns 删除结果\n   */\n  async deleteComment(\n    accessToken: string,\n    videoId: string,\n    commentId: string\n  ): Promise<any> {\n    try {\n      const { data } = await firstValueFrom(\n        this.httpService.post(`${this.apiBaseUrl}/v2/comment/delete/`, {","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-electron/server/src/modules/plat/tiktok/tiktok.service.ts#L790-L826","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"if (!commentDto?.videoId || !commentDto?.text?.trim()) {\n  throw new Error('videoId and non-empty text are required');\n}\nif (commentDto.text.length > 150) {\n  throw new Error('comment text exceeds TikTok length limit');\n}","typeGuard":"function isValidCommentDto(d: unknown): d is { videoId: string; text: string } {\n  const o = d as any;\n  return typeof o?.videoId === 'string' && o.videoId.length > 0\n    && typeof o?.text === 'string' && o.text.trim().length > 0;\n}","tryCatchPattern":"try {\n  await tiktokService.postComment(token, dto);\n} catch (e) {\n  if (/permission|not approved|scope/i.test(e.message)) {\n    // app lacks comment-post access: apply via TikTok developer portal\n  } else if (/spam|frequent/i.test(e.message)) {\n    // throttle: queue the comment and slow down\n  } else throw e;\n}","preventionTips":["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."],"tags":["tiktok","comments","http-client","permissions"],"backgroundTag":"insufficient-api-scope","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}