Search code examples
phpgoogle-drive-apigoogle-api-php-client

How to untrash a Google Drive file with PHP Google API client?


The official documentation says:

/*
 * @param Google_Service_Drive $service Drive API service instance.
 */
$service->files->untrash($fileId);

But there is no such method in the library, if I call this I get:

[Error]                                                                  
  Call to undefined method Google\Service\Drive\Resource\Files::untrash()

My client library version is:

"google/apiclient": "^2.12.1",

Solution

  • Client library version 2.12.1 uses Google Drive API v3, this new version doesn't have an untrashed() method but you can use update() instead, try this:

    $FileMetadata = new Google_Service_Drive_DriveFile(
        array(
            'trashed' => false
        )
    );
    
    $service->files->update($fileId,$FileMetadata);
    

    I found this post with additional examples of the differences between v2 and v3. You can also find more samples for this new version here.