Angular10与BigQuery,获取访问被拒绝:BigQuery BigQuery:获取驱动器凭据时权限被拒绝



我正在使用'@google cloud/BigQuery'集成Angular10、Firebase和BigQuery。我在我的项目中创建了一个函数文件夹,并在其中添加了密钥json文件,该文件是我在谷歌云控制台上生成服务帐户json后获得的。

我的BigQuery面板中有两个数据集,其来源是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,我们无法连接到云服务。您可以指定一个名为"的环境变量;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']);
}

最新更新