我正在尝试使用 Node.js 使用 Google 电子表格 API 创建新的 Google 电子表格
我已成功让 Google OAuth 2.0 正常运行,并为客户端获取访问 token 。
现在在搜索 Google API 文档时,有使用 gData 客户端库的示例,但没有任何内容给我指向 node.js
以下是我创建新的 Google Spreadhseet 的发现
- 手动上传电子表格或
- 使用可续传上传链接
关于断点续传链接的信息不多。
我可以看到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/