将工作表插入Google工作表

时间:2017-08-29 20:30:17

标签: javascript google-sheets-api

我尝试使用浏览器中的java脚本在新的工作表中插入并命名新的工作表。

Google's OAuth Playground中使用Spreadsheets V3 API尝试插入工作表(VIA"插入工作表"操作)时,我收到错误415:" Content-Type application / json不是有效的输入类型。"

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

是否有人知道正确的内容类型/如何使用java脚本浏览器代码将工作表插入Google表格?

谢谢!

概要/解决方案:

1 个答案:

答案 0 :(得分:1)

Spreadsheets v3现在是旧版本: enter image description here

您可以使用v4migration 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"
  }
}

此请求在我的驱动器中成功创建了一个工作表: enter image description here

希望这有帮助。