首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >谷歌电子表格创建- Node.js

谷歌电子表格创建- Node.js
EN

Stack Overflow用户
提问于 2012-09-27 21:48:47
回答 4查看 1.9K关注 0票数 1

我正在尝试使用node.js的google spreadsheet api创建新的google spreadsheet

我已经设法让谷歌OAuth 2.0正常工作,我正在为客户端获取访问令牌。

现在搜索Google API文档,有使用gData客户端库的示例,但没有给出指向node.js的指针

这是我创建一个新的google spreadhseet的发现

  1. 手动上载电子表格或
  2. 使用可恢复的上载链接

关于可恢复上传链接的信息不多。

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

编辑--

我正在读Google Apps Platform

EN

回答 4

Stack Overflow用户

发布于 2017-06-05 06:16:53

下面是如何使用Google Sheets API (当前为v4)的create方法完成此操作。

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

代码语言:javascript
复制
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);
});
票数 1
EN

Stack Overflow用户

发布于 2012-09-28 09:28:20

如果您只想知道如何构造post请求,请查看此示例

http://nodejs.org/api/http.html#http_http_request_options_callback

票数 0
EN

Stack Overflow用户

发布于 2013-02-06 11:42:07

结帐

https://github.com/EastCloud/node-spreadsheets/

EastCloud为Google Docs/Drive API编写了一个友好的包装器

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12622947

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档