确认您启用了“Cloud Scheduler”和“Cloud Functions API”两个服务。在 Cloud Console 中,转到“API和服务”页面,启用这两个服务。
将以下代码放入您的 Cloud Functions 中,用于启用定期查询 API:
const {google} = require('googleapis');
const bigqueryadmin = google.bigquery('v2');
const PROJECT_ID = 'your_project_id';
async function enableScheduledQueriesAPI() {
try {
await bigqueryadmin.projects.enable({
auth: authClient,
projectId: PROJECT_ID,
});
console.info(`Scheduled Queries API has been enabled for ${PROJECT_ID}.`);
} catch (error) {
console.error(`Unable to enable Scheduled Queries API: ${error}`);
}
}
"roles/bigquery.admin"
或 "roles/bigquery.jobUser"
角色。运行 Cloud Functions 后,您应该已经可以启用 BigQuery 定期查询 API,并且不再报错。