Google Sheets API最小示例 [英] Google sheets API minimal example

查看:116
本文介绍了Google Sheets API最小示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 google-spreadsheet npm软件包从第一个获取数据已与服务帐户共享的Google表格的2个标签.由于这是一项简单的任务,因此我想删除对第三方软件包的依赖,并直接使用Google的库.但是,有很多不同的Google库,我不确定该使用什么.

I am using the google-spreadsheet npm package to fetch data from the first 2 tabs of a Google Sheet which has been shared with a service account. Since this is a simple task, I would like to remove the dependency on a third party package and use Google's libraries directly. However, there are many different Google libraries and I am not sure what to use.

以下是我当前正在使用的基于Google电子表格的代码.如何将其转换为直接使用Google库?

Below is the google-spreadsheet based code I am currently using. How can I convert this to directly use Google libraries?

var GoogleSpreadsheet = require('google-spreadsheet');
var creds = require('./credentials.json');

var doc = new GoogleSpreadsheet('### spreadsheet id ###');

doc.useServiceAccountAuth(creds, function(err) {
    doc.getRows(1, function(err, rows) {
        console.log(rows);
    });
    doc.getRows(2, function(err, rows) {
        console.log(rows);
    });
});

推荐答案

这是 Google官方支持的Node.js客户端库,用于访问Google API.这涵盖了所有类型的身份验证,包括使用服务帐户.我以为这就是您要寻找的东西.

This is Google's officially supported Node.js client library for accessing Google APIs. This covers all types of authentication, including using a Service Account. I assume this is what you're looking for.

此外,在Google Sheets API 官方文档中,您可以在以下位置找到该库的许多示例使用.

Also, in Google Sheets API official documentation you can find many examples of this library in use.

一方面,有快速入门,其中对此进行了说明,逐步介绍如何设置应用程序以进行调用(在示例中,它从电子表格中的指定范围获取值,如果我理解正确的话,这就是您要执行的操作).

On one side, there is a quickstart in which it is explained, step by step, how to set your application to make a call (in the example, it gets the values from a specified range in a spreadsheet, which, if I understood correctly, is what you want to do).

另一方面,您可以找到该API大部分方法所使用的该库的示例.

On the other side, you can find examples of this library in use for most of this API methods in the reference tab.

我希望这会有所帮助.

这篇关于Google Sheets API最小示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆