How to update file in google drive v3 PHP

前端 未结 2 1849
别跟我提以往
别跟我提以往 2021-02-15 17:34

I cant seem to update file in google drive with the following code, everything goes fine but file remains untouched? I am working with v3 api.

 function updateFi         


        
2条回答
  •  悲哀的现实
    2021-02-15 18:04

     function updateFile($fileId,$newDescription){
            try {    
                // First retrieve the file from the API. 
                $emptyFile = new Google_Service_Drive_DriveFile();
                // File's new metadata.   
                $emptyFile->setDescription($newDescription);
                // Send the request to the API.
                $driveService->files->update($fileId, $emptyFile, array());
                print 'success';
            } catch (Exception $e) {
                print "An error occurred: " . $e->getMessage();
            }
        }//end update
    

    The method is essential if you wish to update staff like desciption. I copied the idea from v2.

    // File's new metadata.
    $file->setTitle($newTitle);
    $file->setDescription($newDescription);
    $file->setMimeType($newMimeType);
    

    NB: Also you have to ensure 3 parameter of update function is an array Also as stated in other helpful answer; Ensure you refresh google drive to check

提交回复
热议问题