【发布时间】:2016-11-03 08:19:21
【问题描述】:
我想实现 Google BigQuery API,以便可以在 BigQuery 中从我的 PHP 代码执行查询。
首先我通过以下命令安装了客户端库:
composer require google/cloud
其次,我通过以下命令安装了 Google Cloud SDK:
curl https://sdk.cloud.google.com | bash
然后我运行这个命令来创建凭证:
gcloud beta auth application-default login
所有过程都成功,运行凭据请求后,我收到以下消息:
Credentials saved to file:
[/home/some/my/dir/application_default_credentials.json]
These credentials will be used by any library that requests
Application Default Credentials.
然后我想在 PHP 上运行这段代码:
# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
# Imports the Google Cloud client library
use Google\Cloud\BigQuery\BigQueryClient;
# Your Google Cloud Platform project ID
$projectId = 'PROJECT ID';
# Instantiates a client
$bigquery = new BigQueryClient([
'projectId' => $projectId
]);
# The name for the new dataset
$datasetName = 'my_new_dataset';
# Creates the new dataset
$dataset = $bigquery->createDataset($datasetName);
echo 'Dataset ' . $dataset->id() . ' created.';
但不幸的是,我收到以下消息错误:
Fatal error: Uncaught exception 'Google\Cloud\Exception\ServiceException' with message 'Could not load the default credentials
所以我的问题是:出了什么问题,我必须做什么?
谢谢
【问题讨论】:
-
您的费率很低。对 SO 很重要,您必须使用已发布答案左侧、投票下方的勾号来标记已接受的答案。这将提高您的费率。通过访问此链接了解其工作原理:meta.stackoverflow.com/questions/5234/…
标签: php google-bigquery