这是我目前的代码,只带回一个项目。 我如何获得所有可访问项目的列表?
# Includes the autoloader for libraries installed with composer
require __DIR__ . '/../vendor/autoload.php';
# Imports the Google Cloud client library
use Google\Cloud\BigQuery\BigQueryClient;
$client = new Google_Client();
$client->setAuthConfig(__DIR__ . '/../gcp-bigquery-key.json');
$scopes = implode(' ', [Google_Service_Bigquery::BIGQUERY]);
$client->setScopes($scopes);
$service = new Google_Service_Bigquery($client);
$tQ = $service->projects->listProjects();
print_r($tQ);
答案 0 :(得分:0)
我看到您正在使用BigQuery令牌作为授权。由于该键对BigQuery有效,因此您将获得包含该BigQuery的项目。
要查看所有项目,可以检查文档[1]中的以下代码:
require_once __DIR__ . '/vendor/autoload.php';
$client = new Google_Client();
$client->setApplicationName('Google-CloudResourceManagerSample/0.1');
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/cloud-platform');
$service = new Google_Service_CloudResourceManager($client);
$optParams = [];
do {
$response = $service->projects->listProjects($optParams);
foreach ($response['projects'] as $project) {
// TODO: Change code below to process each `project` resource:
echo '<pre>', var_export($project, true), '</pre>', "\n";
}
$optParams['pageToken'] = $response->getNextPageToken();
} while ($optParams['pageToken']);
?>