如何使用XAMPP环境在本地用php访问Google Bigquery

问题描述 投票:0回答:1

我在 XAMPP 服务器上有一个示例 php 文件

<?php

require 'vendor/autoload.php';

use Google\Cloud\BigQuery\BigQueryClient;

putenv('GOOGLE_APPLICATION_CREDENTIALS=D:\xampp\htdocs\weather839\test_key.json'); 

$credentialsTest = getenv('GOOGLE_APPLICATION_CREDENTIALS');
echo 'Credentials Path: ' . $credentialsTest;

$credentialsPath= 'test_key.json';
$projectId = 'hardy-tine-285605';

$bigQuery = new BigQueryClient([
    'projectId' => $projectId,
    'keyFile' => json_decode(file_get_contents($credentialsPath), true),
    // 'location'=>'asia-southeast1'
]);

$query = 'SELECT * FROM hardy-tine-285605.test.station_list Limit 1000;';
$queryJobConfig = $bigQuery->query($query);
$queryJob = $bigQuery->startQuery($queryJobConfig);


$queryJob->waitUntilComplete();
$queryResults = $queryJob->queryResults();
$data = [];
foreach ($queryResults as $row) {
    $data[] = $row;
}

header('Content-Type: application/json');
echo json_encode($data);

?>

它总会回来的

致命错误:未捕获 Google\Cloud\Core\Exception\ServiceException:cURL 错误 7:无法连接到 bigquery.googleapis.com 端口 443:连接被拒绝

如何访问Bigquery数据?

php google-bigquery authorization
1个回答
0
投票

我使用你的代码连接到我的bigquery,它对我来说工作得很好,所以我想问题必须是凭据或projectid,如果不是,可能是自动加载的路径。

© www.soinside.com 2019 - 2024. All rights reserved.