【发布时间】:2020-04-16 14:35:07
【问题描述】:
如果 Google 表格的数据通过 BigQuery 的 Sheets 数据连接器 来自 BigQuery(如 here 所述),是否可以通过表格 API 强制刷新此 BigQuery 数据?可以通过表格 UI(有一个刷新按钮)执行此操作,但我想通过调用 API 的其他一些服务来执行此操作。
【问题讨论】:
标签: google-sheets google-bigquery
如果 Google 表格的数据通过 BigQuery 的 Sheets 数据连接器 来自 BigQuery(如 here 所述),是否可以通过表格 API 强制刷新此 BigQuery 数据?可以通过表格 UI(有一个刷新按钮)执行此操作,但我想通过调用 API 的其他一些服务来执行此操作。
【问题讨论】:
标签: google-sheets google-bigquery
您可以使用 Apps 脚本与电子表格中的数据连接器进行交互。
您无法通过 Sheet API 操作数据源。您可以改用 Apps 脚本。设置刷新 BigQuery 数据的脚本相对容易。
如果您想使用外部 API 执行此操作,则必须使用 Apps 脚本作为代理来实现您的目标。您可以将您的 Apps 脚本部署为 API 可执行文件,并从外部服务触发其功能。
/** @OnlyCurrentDoc */
function refresh() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A1').activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Data Sheet 1'), true);
SpreadsheetApp.enableAllDataSourcesExecution();
spreadsheet.getCurrentCell().getDataSourceTables()[0].refreshData();
};
// [...] Oauth and other set ups...
public static void main(String[] args) throws IOException {
// ID of the script to call. Acquire this from the Apps Script editor,
// under Publish > Deploy as API executable.
String scriptId = "ENTER_YOUR_SCRIPT_ID_HERE";
Script service = getScriptService();
// Create an execution request object.
ExecutionRequest request = new ExecutionRequest()
.setFunction("refresh");
try {
// Make the API request.
Operation op =
service.scripts().run(scriptId, request).execute();
// [...] Error handling...
【讨论】: