【问题标题】:Angular10 with BigQuery , Getting Access Denied: BigQuery BigQuery: Permission denied while getting Drive credentials带有 BigQuery 的 Angular10,拒绝访问:BigQuery BigQuery:获取驱动器凭据时权限被拒绝
【发布时间】:2021-08-27 22:00:45
【问题描述】:

我正在使用“@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”的环境变量指定一个

有人可以帮我吗?

【问题讨论】:

    标签: firebase google-bigquery angular10


    【解决方案1】:

    要解决此问题,您需要在 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']);
            }
    

    【讨论】:

      猜你喜欢
      • 2021-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-06
      • 2021-09-04
      • 1970-01-01
      相关资源
      最近更新 更多