首页 > 解决方案 > PHP示例下GCP setIamPolicy API参考中的问题

问题描述

在此页面上https://cloud.google.com/resource-manager/reference/rest/v1/projects/setIamPolicy

底部是代码示例。PHP 代码如下。问题是线路

$response = $service->projects->setIamPolicy($resource, $requestBody);

没有定义的“项目”属性。我猜这已经过时了。任何人都可以描述应该如何使用它,或者提供更正吗?

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);

// REQUIRED: The resource for which the policy is being specified.
// See the operation documentation for the appropriate value for this field.
$resource = 'my-resource';  // TODO: Update placeholder value.

// TODO: Assign values to desired properties of `requestBody`:
$requestBody = new Google_Service_CloudResourceManager_SetIamPolicyRequest();

$response = $service->projects->setIamPolicy($resource, $requestBody);

// TODO: Change code below to process the `response` object:
echo '<pre>', var_export($response, true), '</pre>', "\n";

标签: phpgoogle-cloud-platformgoogle-api-php-clientgoogle-iam

解决方案


我不认为该示例已经过时,我认为它假设您已经查看了其他文档:

https://cloud.google.com/resource-manager/reference/rest/v1/projects/get

不过,如果您认为信息丢失,您可以按文档右上角的“发送反馈”。

祝你好运!


推荐阅读