简体   繁体   中英

PHP upload a file on google Drive

I am learning google drive API and from this documentation ( https://developers.google.com/drive/v3/web/manage-uploads ) there is a code example but somewhere in the code, I find something wrong.

This is the code in the google api documentaiton:

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

But I do not know, how this piece of code works since $driveService was not initialized before or it is null

$file = $driveService->files->create($fileMetadata, array(
      'data' => $content,
      'mimeType' => 'image/jpeg',
      'uploadType' => 'multipart',
      'fields' => 'id')); 

Can someone help me please. Thank you very much.

You forgot to read the quickstart first.

https://developers.google.com/drive/v3/web/quickstart/php

Full PHP Implement is in step 3 and the service is $service = new Google_Service_Drive($client);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM