首页 > 解决方案 > 新项目的 Youtube 配额

问题描述

我第一次将 Youtube API 与 Apps 脚本一起使用,但出现配额错误。我从 Apps Script 窗口激活了 Youtube API,并添加了我的脚本。

注意我使用的是 Google Workspace 帐户。我的私人谷歌帐户没有这个问题。

这是生成错误的代码:

    function getVids() {
  var list = YouTube.Search.list('id,snippet', {
    channelId: 'UCYf_kU_HoMOUUe3hW-0ou5Q',
    maxResults: 25
  })

  var json = JSON.parse(list);
  var items = list.items;
  var allVideos = [];
  for (var i=1; i<items.length;i++) {
    var videoId = list.items[i].id.videoId;
    allVideos.push(videoId);
  }
  console.log(allVideos)
}

我收到此错误:

GoogleJsonResponseException: API call to youtube.videos.insert failed with error: The request cannot be completed because you have exceeded your quota

我试着在这里查看消费情况:https ://console.developers.google.com/apis/dashboard但它会将我重定向到https://console.developers.google.com/apis/dashboard?project=northern-math- 286006&folder=&organizationId=我认为这是一些默认项目名称,因为我没有选择它。我从此页面选择了https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?folder=&organizationId=&project=northern-math-286006来查看 Youtube 数据,但它返回“无数据在选定的时间范围内可用。”

标签: google-apps-scriptyoutube

解决方案


解释:

根据官方文档,您每天已超过10,000 个单位。

单位点可能有点难以理解,但上面的链接本身有一个很好的解释:

在此处输入图像描述

您正在执行搜索请求,并且对于每个搜索请求,您花费100 个单位。我假设您已经执行了此代码和/或其他消耗积分的代码,这就是您达到最大单位积分的原因。

根据此处的文档,您可以查看您的配额使用情况,但您可能需要获得访问该信息的权限。

YouTube 数据 API (v3) - 配额计算器

如果您的应用程序调用返回多页结果的方法(例如 search.list),则检索额外结果页的每个请求都会产生估计的配额成本。


推荐阅读