How to create project in Google Console Cloud platform using PHP Lib programmatically?
Asked Answered
C

1

3

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

Steps taken/ Got the issue:

  1. This line " $requestBody = new \Google_Service_CloudResourceManager_Project(); ".

    Throwing error : 'Class Google_Service_CloudResourceManager_Project not found'.

    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)

  2. 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).

    Throwing error : Call to a member function create() on null at this line "$response = $service->projects->create($requestBody);".

My Google OAuth script is working fine, only issue with this project create script

PHP Script:

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

enter image description here

Cubbyhole answered 19/9, 2020 at 17:31 Comment(0)
C
1

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.

Castleberry answered 21/9, 2020 at 14:55 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.