Google APIs 学习/使用

本文介绍了如何利用Google提供的APIs在项目中操作Google文档,重点讲解了Google Sheets API的使用方法,包括如何通过代码获取和更新数据,以及解决在Node.js环境下获取行数的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.应用场景

了解并使用Google APIs, 用于开发当中.

2.学习/操作

背景:

公司开发有用到Google APIs,所以只能去了解.

 

1.介绍

简单说, 就是Google提供操作Google文档的api,

方便在项目使用code进行操作.

 

2.操作

https://developers.google.com/apis-explorer  //Google APIs Explorer

https://developers.google.com/sheets/api/reference/rest  //在Google APIs Explorer, 搜索sheets之后的结果

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values  //REST Resource: spreadsheets.values

 

后续补充

...

3.问题/补充

1.如何使用api获取Google Spreadsheet中的行数?

参考: https://stackoom.com/question/178iy/如何使用api获取Google-Spreadsheet中的行数

 

查了文档,以及Google搜索之后,发现只是支持Python进行查询获取rowCount

nodeJS解决办法:

折中办法,自行记录rowCount,然后获取.

async function updateRowsCount(sheets, spreadsheetId, sheetName){
    const res = await sheets.spreadsheets.values.update({
        spreadsheetId: spreadsheetId,
        range: `${sheetName}!${LastRowCountCell}`,
        valueInputOption: 'USER_ENTERED',
        requestBody: {
            values: [
                ['=COUNT(A:A)'],
            ],
        },
    })
    return res.data;
}

这种办法,会每次更新rowCount,然后再查询获取rowCount值

 

优化:

应该继续查询文档或者nodeJS组件,或者可以考虑自己试着去写组件。//TBD

4.参考

https://github.com/googleapis/google-api-nodejs-client/#google-apis  //googleapis/google-api-nodejs-client

https://developers.google.com/apis-explorer  //Google APIs Explorer

https://stackoverflow.com/questions/61749543/how-to-get-the-correct-parameters-for-the-googleapi-nodejs-client //How to get the correct parameters for the googleapi-nodejs-client

后续补充

...

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值