yikart/AiToEarn · error · Error

当前账号未启用 YouTube,请先创建频道

Error message

当前账号未启用 YouTube,请先创建频道

What it means

In uploadVideo's catch block around channels.list(mine=true), when Google rejects the request with error reason 'youtubeSignupRequired', the service rethrows this friendlier Error. It means the authenticated Google account is not enrolled with YouTube at all — YouTube features (including the Data API) are unavailable for that identity until a channel exists.

Source

Thrown at project/aitoearn-electron/server/src/modules/plat/youtube/youtube.service.ts:691

      // 设置 OAuth2 客户端凭证
      this.oauth2Service.setCredentials(accessToken);
      const oauth2Client = this.oauth2Service.getClient();

      try {
        const channelInfo = await this.youtubeService.channels.list({
          part: ['snippet'],
          mine: true,
          auth: oauth2Client,
        });

        if (!channelInfo.data.items || channelInfo.data.items.length === 0) {
          throw new Error('未检测到可用的 YouTube 频道,请先创建频道');
        }

        // 可以上传
      } catch (err) {
        if (err.errors?.[0]?.reason === 'youtubeSignupRequired') {
          throw new Error('当前账号未启用 YouTube,请先创建频道');
        }
      }


      // 准备视频的元数据
      const fileStream = Readable.from(file.buffer); // 使用文件的 Buffer 转为可读取流
      const fileSize = file.size;  // 获取文件大小

      // 构造请求体
      let requestBody: any = {
        snippet: {
          title: title,
          description: description,
          // tags: keywords ? keywords.split(',') : [],
          tags: keywords ? keywords : [],
          categoryId: categoryId || '22', // 默认 categoryId 为 '22',如果没有指定
        },
        status: {

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Open youtube.com with the exact linked Google account and finish channel creation, then retry the upload.
  2. Re-authorize the account in the app after activation so scopes/token are refreshed.
  3. Confirm via GET https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true that items is non-empty.
  4. If it is a Workspace account, have the admin enable YouTube or link a personal account instead.

Example fix

// before
// upload attempted directly with a non-YouTube Google identity
// after
const res = await fetch('https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true', { headers: { Authorization: `Bearer ${token}` } });
const data = await res.json();
if (!data.items?.length) throw new Error('Enable YouTube / create a channel for this Google account first');
Defensive patterns

Strategy: validation

Validate before calling

const res = await fetch('https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true', { headers: { Authorization: `Bearer ${token}` } });
const body = await res.json();
const reason = body?.error?.errors?.[0]?.reason;
if (reason === 'youtubeSignupRequired') throw new Error('YouTube not enabled for this Google account');

Type guard

function isSignupRequired(err: { errors?: { reason?: string }[] }): boolean {
  return err.errors?.[0]?.reason === 'youtubeSignupRequired';
}

Try / catch

try {
  await upload();
} catch (e) {
  if (isSignupRequired(e) || String(e.message).includes('当前账号未启用 YouTube')) {
    redirectToYouTubeChannelCreation();
  } else throw e;
}

Prevention

When it happens

Trigger: Any upload attempt where the channels.list probe (or the upload itself) returns err.errors[0].reason === 'youtubeSignupRequired'; typically accounts created via Google sign-up that never activated YouTube.

Common situations: Google Workspace/enterprise accounts with YouTube disabled; freshly created service-adjacent Google accounts; users switching the linked account in the app to one that has no YouTube presence.

Related errors


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