- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
所以基本上我尝试了 this来自第二个答案,但它有一个错误
Fatal error: Call to undefined method Google_Client::setAssertionCredentials() in
这是我的代码
require_once 'xxx/vendor/autoload.php';
public function createGClient() {
define("CLIENT_ID", "xxx.apps.googleusercontent.com");
define("SERVICE_ACCOUNT_NAME","xxx@xxx.ccc");
define("KEY_FILE",'xxx');
define("PROJECT_ID","xxx");
define("DATASET_ID","xxx");
define("TABLE_ID","xxx");
$this->client = new Google_Client();
$this->client->setApplicationName("Test");
$key = file_get_contents(KEY_FILE);
$this->client->setAssertionCredentials(
Google_Auth_AssertionCredentials(SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/bigquery'), $key, "notasecret"));
$this->client->setClientId(CLIENT_ID);
$this->service = new Google_Service_Bigquery($this->client);
}
public function runQuery() {
// To see the a list of tables
print_r($this->service->tables->listTables(PROJECT_ID, DATASET_ID));
// To see details of a table
print_r($this->service->tables->get(PROJECT_ID, DATASET_ID, TABLE_ID));
// To query a table
$jobs = $this->service->jobs;
$query = new Google_Service_Bigquery_QueryRequest();
$query->setQuery("SELECT * FROM wherever;");
$response = $jobs->query(PROJECT_ID, $query);
print_r($response);
}
我已经安装了指南/文档中的所有内容。有人可以帮助我吗,因为我尝试了所有方法但都没有用,非常感谢。
最佳答案
不再使用该版本的 PHP 库,因为它已过时且缺少文档。
下面有一个较新的链接,它需要设置服务帐户默认凭据,请参阅 putenv
和 useApplicationDefaultCredentials()
行。这是我使用库 https://github.com/google/google-api-php-client 的工作代码您需要从控制台获取您的服务帐户 key 文件:https://console.cloud.google.com/iam-admin/serviceaccounts/
composer.json
{
"require": {
"google/cloud": "^0.13.0",
"google/apiclient": "^2.0"
}
}
php文件
# Imports the Google Cloud client library
use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\ServiceBuilder;
$query="SELECT repository_url,
repository_has_downloads
FROM [publicdata:samples.github_timeline]
LIMIT 10";
$client = new Google_Client();
putenv('GOOGLE_APPLICATION_CREDENTIALS='.dirname(__FILE__) . '/.ssh/dummyname-7f0004z148e1.json');//this can be created with other ENV mode server side
$client->useApplicationDefaultCredentials();
$builder = new ServiceBuilder([
'projectId' => 'edited',
]);
$bigQuery = $builder->bigQuery();
$job = $bigQuery->runQueryAsJob($query);
$info=$job->info();
// print_r($info);
// exit;
$queryResults = $job->queryResults();
/*$queryResults = $bigQuery->runQuery(
$query,
['useLegacySql' => true]);*/
if ($queryResults->isComplete())
{
$i = 0;
$rows = $queryResults->rows();
foreach ($rows as $row)
{
$i++;
$result[$i] = $row;
}
}
else
{
throw new Exception('The query failed to complete');
}
print_r($result);
关于php - BigQuery PHP 调用未定义的方法 Google_Client::setAssertionCredentials(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41671769/
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
所以基本上我尝试了 this来自第二个答案,但它有一个错误 Fatal error: Call to undefined method Google_Client::setAssertionCrede
此错误对 Youtube API v3.0 意味着什么: A client error occurred: Could not create storage directory: /tmp/Googl
我正在使用核心报告 API 进行报告。我在我的本地主机服务器上安装了 Google PHP API 客户端主机,并在我包含的 src 文件夹中创建了一个文件 HelloAnalyticsAPI.php
我正在使用 Google PHP 客户端库来访问 Google API(参见 reference) 我正在尝试从私有(private)博客中获取帖子列表(与 RSS 提要中的内容相同)。私有(priv
我是一名优秀的程序员,十分优秀!