如何以编程方式使用PHP Lib在Google Console Cloud平台中创建项目? [英] How to create project in Google Console Cloud platform using PHP Lib programmatically?

查看:98
本文介绍了如何以编程方式使用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

已采取的步骤/遇到了问题:

  1. 此行" $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).

抛出错误:在此行"$response = $service->projects->create($requestBody);"处以空值调用成员函数create().

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>', "\n";

die;

推荐答案

似乎这是Google内部的问题.我重新创建了您的方案,并得到了相同的结果.我联系了Cloud App Engine工程团队,并重定向了您的请求.另外,我们已经打开了公共票证,并且与Google的所有通信将在此处继续.

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.

这篇关于如何以编程方式使用PHP Lib在Google Console Cloud平台中创建项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆