node.js - Google 电子表格创建 - Node.js

标签 node.js google-sheets google-sheets-api

我正在尝试使用 Node.js 使用 Google 电子表格 API 创建新的 Google 电子表格

我已成功让 Google OAuth 2.0 正常运行,并为客户端获取访问 token 。

现在在搜索 Google API 文档时,有使用 gData 客户端库的示例,但没有任何内容给我指向 node.js

以下是我创建新的 Google Spreadhseet 的发现

  1. 手动上传电子表格或
  2. 使用可续传上传链接

关于断点续传链接的信息不多。

我可以看到HTTP Post请求和响应,但我不明白如何在node.js中构建post请求

编辑--

我正在阅读Google Apps Platform

最佳答案

以下是如何使用create来做到这一点Google Sheets API的方法(当前为 v4)。

此代码示例不使用任何第三方库,它使用 googleapis: Google API's official Node.js client

const google = require('googleapis');
const sheets = google.sheets('v4');

// authenticate, and store that authentication, in this example
// it is stored in a variable called `auth`. I am using JWT 
// authentication, but you can use the any form of authentication

const auth = new google.auth.JWT(
  key.client_email,
  null,
  key.private_key,
  ['https://www.googleapis.com/auth/spreadsheets'], // make sure that your auth scope includes `spreadsheets`, `drive` or `drive.file`
  null
);

sheets.spreadsheets.create({
  auth: auth,
  resource: {
    properties: {
      title: 'Title of your new spreadsheet'
    }
  }
}, (err, response) => {
  if (err) {
    console.log(`The API returned an error: ${err}`);
    return;
  }

  console.log('Created a new spreadsheet:')
  console.log(response);
});

关于node.js - Google 电子表格创建 - Node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12622947/

相关文章:

android - 如何在没有 OAuth 的情况下从 Android 应用程序访问谷歌电子表格?

javascript - Google Sheets/Javascript - 检查行和列

file - 如何存储Google Sheets API对文件的响应

node.js - 如何使用 jest 来模拟 Promisified 函数

node.js - 套接字.io : best way to find all sockets of a single user

node.js - 将大对象转换为原始数据类型?

java - 一个请求创建工作表和更新数据

node.js - NodeJS : understanding promise

google-apps-script - 如何使用 setValues() 粘贴从 getValues() 获得的数据?谷歌电子表格

google-sheets - Google Sheets Countif 与 Arrayformula