我是GCP的新手。我在this guide之后创建了一个Bigquery数据集。
现在,我正在尝试使用PHP提取这些数据。为此,我一直关注this other guide。
这是我的代码:
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Google\Cloud\BigQuery\BigQueryClient;
use venor\google\cloud\Core\src\ExponentialBackoff;
$projectId = 'abcd';
$query = 'SELECT * FROM `abcd.TestData.BigD2019` LIMIT 1000';
$bigQuery = new BigQueryClient([
'projectId' => $projectId,
]);
$jobConfig = $bigQuery->query($query);
$job = $bigQuery->startQuery($jobConfig);
$backoff = new ExponentialBackoff(10);
$backoff->execute(function () use ($job) {
print('Waiting for job to complete' . PHP_EOL);
$job->reload();
if (!$job->isComplete()) {
throw new Exception('Job has not yet completed', 500);
}
});
$queryResults = $job->queryResults();
$i = 0;
foreach ($queryResults as $row) {
printf('--- Row %s ---' . PHP_EOL, ++$i);
foreach ($row as $column => $value) {
printf('%s: %s' . PHP_EOL, $column, json_encode($value));
}
}
printf('Found %s row(s)' . PHP_EOL, $i);
?>
尝试运行此代码时,我遇到了以下错误-
致命错误:未捕获的异常'Google \ Cloud \ Core \ Exception \ ServiceException',消息为'{“ error”:{“ errors”:[{“ domain”:“ global”,“ reason”:“ authError”,在C:\ xampp \中的“ message”:“无效凭据”,“ locationType”:“头文件”,“ location”:“授权”}],“代码”:401,“ message”:“无效凭据”}}' htdocs \ vendor \ google \ cloud \ Core \ src \ RequestWrapper.php:336堆栈跟踪:#0 C:\ xampp \ htdocs \ vendor \ google \ cloud \ Core \ src \ RequestWrapper.php(189):Google \ Cloud \ Core \ RequestWrapper-> convertToGoogleException(Object(GuzzleHttp \ Exception \ ClientException))#1 C:\ xampp \ htdocs \ vendor \ google \ cloud \ Core \ src \ RestTrait.php(96):Google \ Cloud \ Core \ RequestWrapper- >发送(对象(GuzzleHttp \ Psr7 \ Request),数组)#2 C:\ xampp \ htdocs \ vendor \ google \ cloud \ BigQuery \ src \ Connection \ Rest.php(218):Google \ Cloud \ BigQuery \ Connection \ Rest-> send('jobs','insert',Array)#3 C:\ xampp \ htdocs \ vendor \ google \ cloud \ BigQuery \ src \ BigQueryClient.php(370):Google \ Cloud \ BigQuery \ Connection \ Rest -> insertJob(数组)# 4 C:在336行上的C:\ xampp \ htdocs \ vendor \ google \ cloud \ Core \ src \ RequestWrapper.php中
我无法找出确切的问题。我猜这可能是由于身份验证造成的。
答案 0 :(得分:0)
use venor\google\cloud\Core\src\ExponentialBackoff;
我注意到的一件事是“供应商”的书写不正确。