Google 工作表:通过一次调用将值更新为多个键
Google sheets: updating values to multiple keys with one call
看来我一次只能用一个键更新一个文件:service.spreadsheets().values().batchUpdate(spreadsheetId=key, body=body).execute()
是否有任何技巧可以使用多个键一次调用更新多个工作簿?
回答"are there any tricks to update multiple workbooks with one call using multiple keys?"
很遗憾,在现阶段,答案是否定的。spreadsheets.values.batchUpdate的终点如下。
POST https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values:batchUpdate
在此端点中,包含一个 spreadsheetId。所以不幸的是,这种方法只能通过一次 API 调用来请求一个电子表格。当然,通过一次 API 调用,多次更新可以是 运行 一张使用 spreadsheets.values.batchUpdate 的电子表格。
例如,如果 the batch requests like Drive API 可以是 运行,则 spreadsheets.values.batchUpdate 可以通过一次 API 调用用于多个电子表格。但在现阶段,这种方法还不能使用。
解决方法
如果 OP 关注 Sheets API 的配额,这个解决方法怎么样?在此解决方法中,使用了带有 Google Apps 脚本的 Web 应用程序。使用 Google Apps 脚本的 "Spreadsheet services" 时,即使更新多个电子表格,Sheets API 的配额也不会减少。此解决方法的流程如下。
- 创建一个您想要通过 Google Apps 脚本的电子表格服务执行的脚本。
- 将脚本部署为 Web 应用程序。
- 此时您也可以通过Web Apps的设置,使用access token来访问Web Apps。
- 像 API 一样使用 Python 脚本来使用 Web 应用程序。
参考文献:
看来我一次只能用一个键更新一个文件:service.spreadsheets().values().batchUpdate(spreadsheetId=key, body=body).execute()
是否有任何技巧可以使用多个键一次调用更新多个工作簿?
回答"are there any tricks to update multiple workbooks with one call using multiple keys?"
很遗憾,在现阶段,答案是否定的。spreadsheets.values.batchUpdate的终点如下。
POST https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values:batchUpdate
在此端点中,包含一个 spreadsheetId。所以不幸的是,这种方法只能通过一次 API 调用来请求一个电子表格。当然,通过一次 API 调用,多次更新可以是 运行 一张使用 spreadsheets.values.batchUpdate 的电子表格。
例如,如果 the batch requests like Drive API 可以是 运行,则 spreadsheets.values.batchUpdate 可以通过一次 API 调用用于多个电子表格。但在现阶段,这种方法还不能使用。
解决方法
如果 OP 关注 Sheets API 的配额,这个解决方法怎么样?在此解决方法中,使用了带有 Google Apps 脚本的 Web 应用程序。使用 Google Apps 脚本的 "Spreadsheet services" 时,即使更新多个电子表格,Sheets API 的配额也不会减少。此解决方法的流程如下。
- 创建一个您想要通过 Google Apps 脚本的电子表格服务执行的脚本。
- 将脚本部署为 Web 应用程序。
- 此时您也可以通过Web Apps的设置,使用access token来访问Web Apps。
- 像 API 一样使用 Python 脚本来使用 Web 应用程序。