如何以编程方式使用 PHP Lib 在 Google Console Cloud 平台中创建项目?
我正在尝试使用 PHP 客户端库在 Google 控制台云中创建一个项目.我从 https://cloud 复制了此示例代码.google.com/resource-manager/reference/rest/v1/projects/create#php
I am trying to create a project in the Google console cloud using the PHP client library. I copied this sample code from https://cloud.google.com/resource-manager/reference/rest/v1/projects/create#php
采取的步骤/遇到问题:
这一行"
$requestBody = new Google_Service_CloudResourceManager_Project();
".
抛出错误:未找到 Google_Service_CloudResourceManager_Project 类".
Throwing error : 'Class Google_Service_CloudResourceManager_Project not found'.
然后我检查了试试这个 API"菜单,我们可以使用 Google API Explorer 将 JSON 传递给 API.我使用 Google API Explorer 进行了测试,结果运行良好.(看截图)
Then I checked in the "Try this API" menu, we can pass the JSON to API with Google API Explorer. I tested with Google API Explorer and the results are working fine. (See screenshot)
注释这一行$requestBody = new Google_Service_CloudResourceManager_Project();
";并尝试传递创建方法所需的 json(因为我已经检查了试试这个 API"菜单).
Commenting this line "$requestBody = new Google_Service_CloudResourceManager_Project();
"
and trying to pass the json required to create method ( as i have checked in "Try this API" menu).
抛出错误:调用成员函数 create()
在这一行的 null 上"$response = $service->projects->create($requestBody);
".
Throwing error : Call to a member function create()
on null at this line "$response = $service->projects->create($requestBody);
".
我的 Google OAuth 脚本工作正常,只有这个项目创建脚本有问题
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);
// TODO: Assign values to desired properties of `requestBody`:
//$requestBody = new Google_Service_CloudResourceManager_Project();
$requestBody = '{
"name": "bob kris project 2",
"projectId": "bk-project-290016"
}';
$response = $service->projects->create($requestBody);
// TODO: Change code below to process the `response` object:
echo '<pre>', var_export($response, true), '</pre>', "
";
die;
推荐答案
这似乎是 Google 内部的问题.我重新创建了您的场景并得到了相同的结果.我联系了 Cloud App Engine 工程团队并重定向了您的请求.另外,我们已经开通了一个公众票,所有与谷歌的交流都会在那里继续.
It seems that this is a Google internal issue. I recreated your scenario and have the same result. I contacted a Cloud App Engine engineering team and redirected your request. Also, we have already opened a public ticket, and all communication with Google will continue there.
相关文章