yikart/AiToEarn · warning · BadRequestException
只能选择一个参数: regionCode, id
Error message
只能选择一个参数: regionCode, id
What it means
videoCategories.list accepts either regionCode (categories for a region) or a specific id (a single category). The controller enforces at most one of the two and throws BadRequestException otherwise.
Source
Thrown at project/aitoearn-electron/server/src/modules/plat/youtube/youtube.controller.ts:344
) {
const accessToken = await this.youtubeAuthService.getUserAccessToken(accountId);
return this.youtubeService.insertCommentThreads(accessToken, snippet);
}
@ApiOperation({ summary: '获取视频类别列表' })
@Get('video/categories/list')
async getVideoCategoriesList(
@GetToken() token: TokenInfo,
@Query('accountId') accountId: string,
@Query('regionCode') regionCode?: string,
@Query('id') id?: string
) {
// 校验确保只有一个参数传递
const params = [regionCode, id];
const nonEmptyParams = params.filter(param => param !== undefined && param !== null && param !== '');
if (nonEmptyParams.length > 1) {
throw new BadRequestException('只能选择一个参数: regionCode, id');
}
const accessToken = await this.youtubeAuthService.getUserAccessToken(accountId);
return this.youtubeService.getVideoCategoriesList(accessToken, id, regionCode);
}
@ApiOperation({ summary: '获取视频列表' })
@Get('videos/list')
async getVideosList(
@GetToken() token: TokenInfo,
@Query('accountId') accountId: string,
@Query('id') id?: string,
@Query('myRating') myRating?: string,
@Query('maxResults') maxResults?: string,
@Query('pageToken') pageToken?: string,
) {
// 校验确保只有一个参数传递
const params = [id, myRating];
const nonEmptyParams = params.filter(param => param !== undefined && param !== null && param !== '');View on GitHub (pinned to d3aa8bea5b)
Solutions
- Call once with regionCode to list all categories for a region, or once with id to fetch one category — never both
- If a category id is known, regionCode is unnecessary; drop it
- Validate query composition client-side before sending
Example fix
// before GET /api/plat/youtube/videoCategories/list?accountId=a®ionCode=US&id=20 // after GET /api/plat/youtube/videoCategories/list?accountId=a®ionCode=US
Defensive patterns
Strategy: validation
Validate before calling
const filters = { regionCode, id };
const count = Object.values(filters).filter(v => v !== undefined && v !== null && v !== '').length;
if (count > 1) throw new Error('Provide either regionCode or id, not both'); Try / catch
try {
const cats = await api.get('/plat/youtube/videoCategories/list', { params });
} catch (e) {
if (e.response?.status === 400 && String(e.response.data?.message).includes('只能选择一个参数')) {
params = params.id ? { id: params.id } : { regionCode: params.regionCode };
}
} Prevention
- Use regionCode (e.g. US) to enumerate categories; id to fetch one — pick per use case
- Drop regionCode when a specific category id is already known
- Validate ISO regionCode format and numeric id before sending
When it happens
Trigger: GET videoCategories/list called with both regionCode=US and id=1 (or id=20).
Common situations: Client merges a region default with a specific category id; spec exploration where both were appended to see behavior; template-based URL builders concatenating all provided options.
Related errors
- 只能选择一个参数: handle, userName, id 或 mine
- 只能选择一个参数: channelId, id, mine
- 只能选择一个参数: allThreadsRelatedToChannelId, id, videoId
- 邮箱参数不能为空
- Invalid ObjectId
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/d09d077e3050eae6.
Report an issue: GitHub.