简体   繁体   English

GCP BigQuery PHP客户端获取项目列表

[英]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.

相关问题 BigQuery [PHP API]获取可访问项目的列表 - BigQuery [PHP API] get list of accessible projects 使用 GCP PHP 客户端库创建文件夹 - Creating folders using GCP PHP Client Libraries BigQuery + PHP客户端中的令牌分页不起作用 - Pagination with token in BigQuery + PHP client not working 如何使用 Google Cloud API(直接或使用 GCP PHP 客户端 SDK)以编程方式从 GCP 项目中列出、添加和删除用户? - How do I use the Google Cloud APIs (directly or using the GCP PHP Client SDK) to List, Add, and Remove Users from a GCP project programmatically? 如何从php中的Asana获取特定于分配的用户和项目的任务列表? - How to get list of tasks specific to assigned user & projects from Asana in php? BigQuery + PHP查询选择获取临时表 - BigQuery + PHP Query Select Get Temporary Table bigquery php 客户端不适用于 Apache 网页(Ubuntu 18.10 服务器) - bigquery php client not working with Apache web page (Ubuntu 18.10 server) BigQuery PHP调用未定义的方法Google_Client :: setAssertionCredentials() - BigQuery PHP Call to undefined method Google_Client::setAssertionCredentials() PHP BigQuery 客户端错误代码:401 running long job - PHP BigQuery Client Error Code: 401 running long job 如何使用 PHP bigquery 客户端库对 bigquery 数据进行分页? - How do I paginate the bigquery data using PHP bigquery client library?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM