yikart/AiToEarn · error · BadRequestException

tweetId, userId和accountId是必须的

Error message

tweetId, userId和accountId是必须的

What it means

Thrown by the getTweetDetail endpoint when the query string is missing 'tweetId' or 'accountId' (or the token id is empty). The controller validates all three inputs before fetching the account's access token and calling the Twitter API for tweet details. It is a 400-level input guard, not a Twitter API failure.

Source

Thrown at project/aitoearn-electron/server/src/modules/plat/twitter/twitter.controller.ts:261

  }

  /**
   * 获取推文详情
   */
  @Get('tweets/detail')
  @ApiOperation({ summary: '获取推文详情' })
  @ApiQuery({ name: 'tweetId', type: 'string', description: '推文ID' })
  // @ApiQuery({ name: 'userId', required: true, description: '用户ID' })
  @ApiQuery({ name: 'accountId', required: true, description: 'Twitter账号ID' })
  async getTweetDetail(
    @GetToken() systemToken: TokenInfo,
    @Query('tweetId') tweetId: string,
    // @Query('userId') userId: string,
    @Query('accountId') accountId: string,
  ) {
    const userId = systemToken.id;
    if (!tweetId || !userId || !accountId) {
      throw new BadRequestException('tweetId, userId和accountId是必须的');
    }

    const accessToken = await this.twitterAuthService.getUserAccessToken(accountId);
    return this.twitterService.getTweetDetail(accessToken, userId, accountId, tweetId);
  }

  /**
   * 获取推文统计数据
   */
  @Get('tweets/metrics')
  @ApiOperation({ summary: '获取推文统计数据' })
  @ApiQuery({ name: 'tweetId', type: 'string', description: '推文ID' })
  // @ApiQuery({ name: 'userId', required: true, description: '用户ID' })
  @ApiQuery({ name: 'accountId', required: true, description: 'Twitter账号ID' })
  async getTweetMetrics(
    @GetToken() systemToken: TokenInfo,
    @Query('tweetId') tweetId: string,
    // @Query('userId') userId: string,

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Add both tweetId and accountId as query parameters to the GET request.
  2. Ensure tweetId is the full numeric Twitter status id string (not truncated or empty).
  3. Verify the request includes a valid system token so userId = systemToken.id is non-empty.
  4. Check the client isn't sending these in the body — this endpoint reads them from @Query().

Example fix

// before
GET /twitter/tweet/detail
// after
GET /twitter/tweet/detail?tweetId=1234567890&accountId=acct_123
Defensive patterns

Strategy: validation

Validate before calling

if (!tweetId || !accountId) throw new Error('tweetId和accountId是必须的');
const url = `/twitter/tweet/detail?tweetId=${encodeURIComponent(tweetId)}&accountId=${encodeURIComponent(accountId)}`;

Type guard

function canFetchDetail(p: unknown): p is { tweetId: string; accountId: string } {
  const o = p as any;
  return typeof o?.tweetId === 'string' && o.tweetId.length > 0 && typeof o?.accountId === 'string' && o.accountId.length > 0;
}

Try / catch

try {
  const detail = await api.get(url);
} catch (e) {
  if (e.response?.status === 400) console.error('缺少必要参数:', e.response.data?.message);
}

Prevention

When it happens

Trigger: GET request to getTweetDetail without ?tweetId=... or ?accountId=... query parameters, or an empty-string tweetId/accountId, or a system token resolving to a falsy userId.

Common situations: Client builds the URL but forgets to URL-encode/append one parameter; accountId is empty because the account was not selected in the UI; calling the endpoint without authenticating so systemToken.id is missing.

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


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