[英]GCP BigQuery PHP client get list of projects
This is my current code that brings back just one project. 这是我当前的代码,仅带回一个项目。 How can i get a list of all accessible projects? 如何获得所有可访问项目的列表?
# 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);
I see that you are using BigQuery token for as authorisation. 我看到您正在使用BigQuery令牌作为授权。 As that key is valid for BigQuery, you are getting the project which contains that BigQuery. 由于该键对BigQuery有效,因此您将获得包含该BigQuery的项目。
For seeing all projects you can check this code found in the documentation [1] : 要查看所有项目,您可以检查文档[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']);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.