0

I am trying to create a new Shared Drive using the Google PHP API.

I am using the code which is in the Google API docs (https://developers.google.com/drive/api/v3/manage-shareddrives) but this is returning an error.

require_once ('vendor/autoload.php'); 

$driveMetadata = new Google_Service_Drive_Drive(array(
    'name' => 'Project Resources'));
$requestId = Uuid::uuid4()->toString();
$drive = $driveService->drives->create($requestId, $driveMetadata, array(
    'fields' => 'id'));
printf("Drive ID: %s\n", $drive->id);

This should be returning the Drive ID but instead I receive the following error:

Fatal error: Class 'Google_Service_Drive_Drive' not found in /home//public_html/blocks/google-api-php-client/test.php on line 31

Is the code example in the Google Docs incorrect or am I being stupid?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Scott Bowers
  • 175
  • 3
  • 13

1 Answers1

0

The following is taken directly from the Read Me and will show you how to properly install the library for use.

download the release

If you abhor using composer, you can download the package in its entirety. The Releases page lists all stable versions. Download any file with the name google-api-php-client-[RELEASE_NAME].zip for a package including this library and its dependencies.

Uncompress the zip file you download, and include the autoloader in your project:

require_once '/path/to/google-api-php-client/vendor/autoload.php';

For additional installation and setup instructions, see the documentation.

Composer

The preferred method is via composer. Follow the installation instructions if you do not already have composer installed.

Once composer is installed, execute the following command in your project root to install this library:

composer require google/apiclient:"^2.0"

Finally, be sure to include the autoloader:

require_once '/path/to/your-project/vendor/autoload.php';
Community
  • 1
  • 1
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • I have already followed the instructions and downloaded the latest stable release. Apologies, i should have included this in my code. – Scott Bowers May 21 '19 at 09:15
  • Then all you need to do is check the paths again. It cant find Google_Service_Drive_Drive which means your path is wrong in the require_once try looking around on your server for autoload.php once you find it use that path. in your code – Linda Lawton - DaImTo May 21 '19 at 09:26
  • I have double checked my path and can confirm that the require is correct. The autoloader file is being loaded correctly. I can add a file to Drive with no problems but it won't work when creating a new shared drive. – Scott Bowers May 21 '19 at 09:28