googleworkspace / php-samples

PHP samples for Google Workspace APIs
Apache License 2.0
288 stars 348 forks source link

PHP Google Drive API #40

Closed GodStar88 closed 5 years ago

GodStar88 commented 5 years ago

Hello. I am php developer and want to upload files using api I saw https://developers.google.com/drive/api/v3/quickstart/php it works well. then i did https://developers.google.com/drive/api/v3/manage-uploads

include 'quickstart.php'; $fileMetadata = new Google_Service_Drive_DriveFile(array( 'name' => 'photo.jpg')); $content = file_get_contents('files/photo.jpg'); $file = $driveService->files->create($fileMetadata, array( 'data' => $content, 'mimeType' => 'image/jpeg', 'uploadType' => 'multipart', 'fields' => 'id')); printf("File ID: %s\n", $file->id);

and ran

I got error.

files (1v_fkI4BUZDZts_ZNp4LgDZcr6oNEfPNm) Getting started (0B5fJx4717Z0yc3RhcnRlcl9maWxl) PHP Notice: Undefined variable: driveService in C:\xampp\htdocs\linkedexchanger.com\php\google\upload.php on line 6

Notice: Undefined variable: driveService in C:\xampp\htdocs\linkedexchanger.com\php\google\upload.php on line 6 PHP Notice: Trying to get property 'files' of non-object in C:\xampp\htdocs\linkedexchanger.com\php\google\upload.php on line 6

Notice: Trying to get property 'files' of non-object in C:\xampp\htdocs\linkedexchanger.com\php\google\upload.php on line 6 PHP Fatal error: Uncaught Error: Call to a member function create() on null in C:\xampp\htdocs\linkedexchanger.com\php\google\upload.php:6 Stack trace:

0 {main}

thrown in C:\xampp\htdocs\linkedexchanger.com\php\google\upload.php on line 6

Fatal error: Uncaught Error: Call to a member function create() on null in C:\xampp\htdocs\linkedexchanger.com\php\google\upload.php:6 Stack trace:

0 {main}

thrown in C:\xampp\htdocs\linkedexchanger.com\php\google\upload.php on line 6 PS C:\xampp\htdocs\linkedexchanger.com\php\google>

Please help, thanks

erickoledadevrel commented 5 years ago

The service is called $service in the quickstart but $driveService in the other sample. We would ideally have those in sync, but it's easily corrected in your code.