yikart/AiToEarn · warning · BadRequestException
只能选择一个参数: id, myRating
Error message
只能选择一个参数: id, myRating
What it means
The YouTube controller's getVideosList endpoint enforces a mutually-exclusive parameter rule: callers may pass `id` (a specific video ID) OR `myRating` (list my rated videos), but not both. When both are non-empty (not undefined/null/''), the controller throws BadRequestException with this message before any YouTube API call is made. It is a client-side input validation guard, not a Google API error.
Source
Thrown at project/aitoearn-electron/server/src/modules/plat/youtube/youtube.controller.ts:365
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 !== '');
if (nonEmptyParams.length > 1) {
throw new BadRequestException('只能选择一个参数: id, myRating');
}
const accessToken = await this.youtubeAuthService.getUserAccessToken(accountId);
return this.youtubeService.getVideosList(accessToken, id, myRating, maxResults, pageToken);
}
@ApiOperation({ summary: '视频上传' })
@UseInterceptors(FileInterceptor('file'))
@Post('videos/upload')
async videoUpload(
@GetToken() token: TokenInfo,
@Body('accountId') accountId: string,
@UploadedFile() file: Express.Multer.File,
@Body('title') title: string,
@Body('description') description: string,
@Body('keywords') keywords?: string,
@Body('categoryId') categoryId?: string,
@Body('privacyStatus') privacyStatus?: string,
@Body('publishAt') publishAt?: DateView on GitHub (pinned to d3aa8bea5b)
Solutions
- Send only one of `id` or `myRating`; omit or leave empty the other query parameter.
- Fix the frontend/SDK to skip undefined/null/empty-string params when building the request.
- If both pieces of data are needed, make two separate calls: one by `id`, one by `myRating`.
- Reproduce locally with curl using a single param to confirm the endpoint works: /youtube/videos?myRating=like&accountId=...
Example fix
// before
await api.get('/youtube/videos', { params: { accountId, id: videoId, myRating: rating } });
// after
await api.get('/youtube/videos', { params: { accountId, ...(rating ? { myRating: rating } : { id: videoId }) } }); Defensive patterns
Strategy: validation
Validate before calling
const params = [videoId, myRating].filter(v => v !== undefined && v !== null && v !== '');
if (params.length > 1) throw new Error('Pass only one of: id, myRating');
if (params.length === 0) throw new Error('One of id or myRating is required'); Type guard
function hasSingleParam<T extends Record<string, unknown>>(o: T, keys: (keyof T)[]): boolean {
const filled = keys.filter(k => o[k] !== undefined && o[k] !== null && o[k] !== '');
return filled.length === 1;
} Try / catch
try {
const videos = await client.getVideosList(accountId, videoId, undefined, maxResults);
} catch (e) {
if (String(e.message).includes('只能选择一个参数')) {
console.warn('Sent both id and myRating; retrying with id only');
} else throw e;
} Prevention
- Build query params via a helper that drops undefined/null/empty-string values.
- Enforce single-choice in UI forms (radio group, not two independent inputs).
- Add a client-side assertion before serializing request params.
- Never hardcode default values for optional mutually-exclusive params.
When it happens
Trigger: Calling GET /youtube/videos with both query params set, e.g. ?id=abc123&myRating=like, or passing empty-string-coerced values that the filter treats as non-empty (any param !== undefined && !== null && !== '').
Common situations: Frontend code building query strings from form state where both fields are filled; SDK wrappers that always serialize both optional params (sending myRating='' plus a real id); API consumers copying example URLs and leaving a second param populated.
Related errors
- 只能选择一个参数: channelId, playListIds, mine
- 只能选择一个参数: playlistId, playlistItemsIds
- No response from Gemini
- video duration is required
- DashScope HappyHorse does not support image_tail
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/28ac67db729d76a5.
Report an issue: GitHub.