【问题标题】:What paramater am I missing for YouTube Data API Insert methodYouTube Data API Insert 方法缺少什么参数
【发布时间】:2020-11-30 13:21:22
【问题描述】:

我正在为这个项目使用 Google 的 Apps 脚本。我正在使用 YouTube 数据 API V3,并且我正在使用 PlaylistItems 类。我正在尝试将视频插入播放列表,并且我已从他们提供的文档中拼凑出我所能做的。

YouTube.PlaylistItems.insert({
  "part": [
    "snippet"
  ],
  "resource": {
    "snippet": {
      "playlistId": "PL5t3YGq3D2WnrLyuYL9WCgprQ2RUcwl8a",
      "position": 0,
      "resourceId": {
        "kind": "youtube#video",
        "videoId": testVidId
        // testVidId is the ID of the video I'm trying to insert
      }
    }
  }
});

当我运行它时,我得到一个错误

Exception: Invalid number of arguments provided. Expected 2-3 only

我的问题是:我缺少什么论据?

【问题讨论】:

  • 通过查看包的实际代码,它看起来应该是requestBody 而不是resource (see here)。他们可能在文档中犯了一个错误,他们像你一样使用resource
  • 他们在 2018 年更改了 this pull request

标签: javascript google-apps-script youtube-api youtube-data-api


【解决方案1】:

我相信你的目标如下。

  • 您想使用 Google Apps 脚本将项目插入播放列表。

修改点:

  • 使用YouTube.PlaylistItems.insert(resource, part)时,参数为resourcepart,分别是一个对象和一个字符串数组。

当你的脚本被修改后,变成如下。

修改脚本:

YouTube.PlaylistItems.insert(
  {
    "snippet": {
      "playlistId": "PL5t3YGq3D2WnrLyuYL9WCgprQ2RUcwl8a",
      "position": 0,
      "resourceId": {
        "kind": "youtube#video",
        "videoId": testVidId
      }
    }
  },
  ["snippet"]
);

注意:

参考:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多