如何以编程方式使用 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 平台中创建项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)