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;