如何以编程方式使用 PHP Lib 在 Google Console Cloud 平台中创建项目?

How to create project in Google Console Cloud platform using PHP Lib programmatically?(如何以编程方式使用 PHP Lib 在 Google Console Cloud 平台中创建项目?)
本文介绍了如何以编程方式使用 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).

抛出错误:调用成员函数 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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Encryption in JavaScript and decryption with PHP(JavaScript 加密和 PHP 解密)
Best solution to protect PHP code without encryption(无需加密即可保护 PHP 代码的最佳解决方案)
PHP AES encrypt / decrypt(PHP AES 加密/解密)
Upgrading my encryption library from Mcrypt to OpenSSL(将我的加密库从 Mcrypt 升级到 OpenSSL)
How to add/remove PKCS7 padding from an AES encrypted string?(如何从 AES 加密字符串中添加/删除 PKCS7 填充?)
How do I upgrade from PHP 7.0 to 7.3 on google cloud platform?(如何在谷歌云平台上从 PHP 7.0 升级到 7.3?)