将工作表插入 Google Sheet

Inserting Worksheets Into Google Sheet

我正在尝试在浏览器中使用 java-script 将新作品sheet插入并命名到现有 Google Sheet 中。

当在 Google's OAuth Playground 中使用 Spreadsheets V3 API 尝试插入作品时 sheet (通过 "Insert Worksheets" 操作),我收到错误 415:"Content-Type application/json is not a valid input type."

我已经尝试使用下拉列表中提供的所有默认内容类型 Google,但它们都会导致上述错误。除了 OAuth 游乐场中的内容外,我一直无法找到 Spreadsheets V3 API 的文档。

有谁知道正确的内容类型/如何使用 java 脚本浏览器代码将作品 sheet 插入到 Google Sheet 中?

谢谢!

Summary/Solution:

Spreadsheets v3 现在是旧版:

您可以使用 v4, and the migration documentation 可以帮助从 v3 转换为 v4。我试过在 OAuth 2.0 中使用 v4 :

POST /v4/spreadsheets HTTP/1.1
Host: sheets.googleapis.com
Gdata-version: 3.0
Content-length: 61
Content-type: application/json
Authorization: Bearer ACCESS_TOKEN
{
  "properties": {
    "title": "Test Sheets (local)2"
  }
}

此请求成功地在我的驱动器中创建了一个 sheet:

希望对您有所帮助。