Updates a revision. Try it now or see an example.
Request
HTTP request
PATCH https://www.googleapis.com/drive/v2/files/fileId/revisions/revisionId
Parameters
Parameter name | Value | Description |
---|---|---|
Path parameters | ||
fileId |
string |
The ID for the file. |
revisionId |
string |
The ID for the revision. |
Authorization
This request requires authorization with at least one of the following scopes:
Scope |
---|
https://www.googleapis.com/auth/drive |
https://www.googleapis.com/auth/drive.file |
https://www.googleapis.com/auth/drive.appdata |
Some scopes are restricted and require a security assessment for your app to use them. For more information, see the authentication and authorization page.
Request body
In the request body, supply the relevant portions of a Revisions resource, according to the rules of patch semantics, with the following properties:
Property name | Value | Description | Notes |
---|---|---|---|
Optional Properties | |||
pinned |
boolean |
Whether this revision is pinned to prevent automatic purging. If not set, the revision is automatically purged 30 days after newer content is uploaded. This field can only be modified on files with content stored in Drive, excluding Docs Editors files. Revisions can also be pinned when they are created through the drive.files.insert/update/copy by using the pinned query parameter. Pinned revisions are stored indefinitely using additional storage quota, up to a maximum of 200 revisions. | writable |
publishAuto |
boolean |
Whether subsequent revisions will be automatically republished. This is only populated and can only be modified for Docs Editors files. | writable |
published |
boolean |
Whether this revision is published. This is only populated and can only be modified for Docs Editors files. | writable |
publishedOutsideDomain |
boolean |
Whether this revision is published outside the domain. This is only populated and can only be modified for Docs Editors files. | writable |
Response
If successful, this method returns a Revisions resource in the response body.
Examples
Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).
Java
Uses the Java client library.
import com.google.api.services.drive.Drive; import com.google.api.services.drive.model.Revision; import java.io.IOException; // ... public class MyClass { // ... /** * Pin a revision. * * @param service Drive API service instance. * @param fileId ID of the file to update revision for. * @param revisionId ID of the revision to pin. * @return The patched revision if successful, {@code null} otherwise. */ private static Revision pinRevision(Drive service, String fileId, String revisionId) { Revision patchedRevision = new Revision(); patchedRevision.setPinned(true); try { return service.revisions().patch( fileId, revisionId, patchedRevision).execute(); } catch (IOException e) { System.out.println("An error occurred: " + e); } return null; } // ... }
.NET
Uses the .NET client library.
using Google.Apis.Drive.v2; using Google.Apis.Drive.v2.Data; using System.Net; // ... public class MyClass { // ... /// <summary> /// Pin a revision. /// </summary> /// <param name="service">Drive API service instance.</param> /// <param name="fileId">ID of the file to update revision for.</param> /// <param name="revisionId">ID of the revision to pin.</param> /// <returns>The patched revision, null is returned if an API error occurred</returns> public static Revision PinRevision(DriveService service, String fileId, String revisionId) { Revision patchedRevision = new Revision(); patchedRevision.Pinned = true; try { return service.Revisions.Patch(patchedRevision, fileId, revisionId).Execute(); } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); } return null; } // ... }
PHP
Uses the PHP client library.
/** * Pin a revision. * * @param Google_Service_Drive $service Drive API service instance. * @param String $fileId ID of the file to update revision for. * @param String $revisionId ID of the revision to pin. * @return Google_Servie_Drive_Revision The patched revision. NULL is returned * if an API error occurred. */ function pinRevision($service, $fileId, $revisionId) { $patchedRevision = new Google_Service_Drive_Revision(); $patchedRevision->setPinned(true); try { return $service->revisions->patch($fileId, $revisionId, $patchedRevision); } catch (Exception $e) { print "An error occurred: " . $e->getMessage(); } return NULL; }
Python
Uses the Python client library.
from apiclient import errors # ... def pin_revision(service, file_id, revision_id): """Pin a revision. Args: service: Drive API service instance. file_id: ID of the file to update revision for. revision_id: ID of the revision to pin. Returns: The patched revision if successful, None otherwise. """ patched_revision = {'pinned': True} try: return service.revisions().patch( fileId=file_id, revisionId=revision_id, body=patched_revision).execute() except errors.HttpError, error: print 'An error occurred: %s' % error return None
JavaScript
Uses the JavaScript client library.
/** * Pin a revision. * * @param {String} fileId ID of the file to update revision for. * @param {String} revisionId ID of the revision to pin. */ function pinRevision(fileId, revisionId) { var body = {'pinned': true}; var request = gapi.client.drive.revisions.patch({ 'fileId': fileId, 'revisionId': revisionId, 'resource': body }); request.execute(function(resp) { }); }
Go
Uses the Go client library.
import ( "google.golang.org/drive/v2" "fmt" ) // PatchRevision patches a revision to be pinned func PatchRevision(d *drive.Service, fileId string, revisionId string) error { r := &drive.Revision{Pinned: true} _, err := d.Revisions.Patch(fileId, revisionId, r).Do() if err != nil { fmt.Printf("An error occurred: %v\n", err) return err } return nil }
Objective-C
Uses the Objective-C client library.
#import "GTLDrive.h" // ... + (void)pinRevisionWithService:(GTLServiceDrive *)service fileId:(NSString *)fileId revisionId:(NSString *)revisionId completionBlock:(void (^)(GTLDriveRevision *, NSError *))completionBlock { GTLDriveRevision *patchedRevision = [GTLDriveRevision object]; patchedRevision.pinned = @YES; GTLQueryDrive *query = [GTLQueryDrive queryForRevisionsPatchWithObject:patchedRevision fileId:fileId revisionId:revisionId]; // queryTicket can be used to track the status of the request. GTLServiceTicket *queryTicket = [service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLDriveRevision *revision, NSError *error) { if (error == nil) { completionBlock(revision, nil); } else { NSLog(@"An error occurred: %@", error); completionBlock(nil, error); } }]; } // ...
Try it!
Use the APIs Explorer below to call this method on live data and see the response.