【问题标题】:Google Spreadsheet Creation - Node.jsGoogle 电子表格创建 - Node.js
【发布时间】:2012-09-27 13:48:47
【问题描述】:

我正在尝试使用 node.js 使用谷歌电子表格 api 创建新的谷歌电子表格

我已经设法让 Google OAuth 2.0 正常工作,我正在那里获取客户端的访问令牌。

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

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

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

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

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

编辑--

我正在阅读Google Apps Platform

【问题讨论】:

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


    【解决方案1】:

    下面是如何使用Google Sheets API 的create 方法(当前为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);
    });
    

    【讨论】:

      【解决方案2】:

      如果您只想知道如何构建发布请求,请查看此示例

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

      【讨论】:

      • 我知道如何在 node.js 中进行发布请求。我想知道我是否要向谷歌发出一个发布请求以创建一个新的电子表格,我应该发布什么链接以及我应该发布什么
      【解决方案3】:

      结帐

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

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

      【讨论】:

        【解决方案4】:

        如果您是新手并想获取数据并将其添加到 Google 电子表格,请参阅以下链接以获取分步指南。

        https://www.twilio.com/blog/2017/03/google-spreadsheets-and-javascriptnode-js.html

        我在最近的 nodejs 项目中进行了相同的测试

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-08-09
          • 2021-08-22
          相关资源
          最近更新 更多