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:
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)
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;
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.