firebase - 带有 BigQuery 的 Angular10,拒绝访问:BigQuery BigQuery:获取驱动器凭据时权限被拒绝
问题描述
我正在使用“@google-cloud/bigquery”将 Angular10、Firebase 与 BigQuery 集成。我在我的项目中创建了一个函数文件夹,并添加了在 Google Cloud Console 上生成服务帐户 json 后获得的密钥 json 文件。
我的 BigQuery 仪表板中有 2 个数据集,其来源是 Google Drive。但是当我尝试查询这些表时,我遇到了错误。
在我的函数文件夹中,我有 index.js 文件,我在其中使用以下内容初始化我的 BigQuery 客户端:
const bigqueryClient = new BigQuery({
keyFilename:'./<name of key Json file from servie account>',
scopes:['https://www.googleapis.com/auth/drive.readonly'],
projectId:<Project-id>
});
我收到的错误:“访问被拒绝:BigQuery BigQuery:获取云端硬盘凭据时权限被拒绝。”
此外,如果我在初始化我的大查询客户端时删除了 projectId,控制台上会记录以下错误:
抱歉,没有项目 ID,我们无法连接到云服务\n。您可以使用名为\n "GOOGLE_CLOUD_PROJECT" 的环境变量指定一个
有人能帮我一下吗?
解决方案
要解决此问题,您需要在 BigQueryClient 文件中定义您的范围,该文件位于 bigquery 库结构 application/libraries/bigqueryclient/vendor/google/cloud-bigquery/src/BigQueryClient
路径的以下路径中。
进行以下更改
const SCOPE=['https://www.googleapis.com/auth/drive','https://www.googleapis.com/auth/bigquery',];
const INSERT_SCOPE = 'https://www.googleapis.com/auth/bigquery.insertdata';
public function __construct(array $config = [])
{
$this->location = $this->pluck('location', $config, false);
$this->setHttpRetryCodes([502]);
$this->setHttpRetryMessages([
'rateLimitExceeded',
'backendError'
]);
$config += [
'scopes' => self::SCOPE,
'projectIdRequired' => true,
'returnInt64AsObject' => false,
'restRetryFunction' => $this->getRetryFunction(),
//@codeCoverageIgnoreStart
'restCalcDelayFunction' => function ($attempt) {
return min(
mt_rand(0, 1000000) + (pow(2, $attempt) * 1000000),
self::MAX_DELAY_MICROSECONDS
);
}
//@codeCoverageIgnoreEnd
];
$this->connection = new Rest($this->configureAuthentication($config));
$this->mapper = new ValueMapper($config['returnInt64AsObject']);
}
推荐阅读
- java - 通过一列的聚合映射实体
- mysql - django.db.utils.OperationalError: (2026, 'SSL connection error: SSL_CTX_set_tmp_dh failed') 同时连接到本地主机 MYSQL
- r - 'git2r_clone' 中的错误:尝试在 R 中克隆存储库时不受支持的 URL 协议
- apache-spark - 尝试访问 UDF 中的广播变量时,Spark 无限期冻结
- java - Dropwiazrd @CacheControl 未应用缓存控制标头
- vba - 如何使 VBA 宏窗体可扩展?
- android - 在 Flutter for BottomModalSheet 小部件中找不到脚手架错误,即使它是在脚手架内定义的
- excel - GetOpenFile 中的 InitialFileName 问题
- swift - 在 InsertItems(at:) 之后未调用 UICollectionView cellForItemAt - 如何预加载下一个单元格?
- algorithm - 如何用递归证明插入排序的正确性?