Skip to content

Instantly share code, notes, and snippets.

@jmealo
Last active September 8, 2016 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmealo/44d64a3cfa5234e37a6e071cadc7def9 to your computer and use it in GitHub Desktop.
Save jmealo/44d64a3cfa5234e37a6e071cadc7def9 to your computer and use it in GitHub Desktop.

Folders

  • A folder is a file with the MIME type application/vnd.google-apps.folder and with no extension.
  • You can use the alias root to refer to the root folder anywhere a file ID is provided
  • To insert a file in a particular folder, specify the correct ID in the parents property of the file.
  • The parents property can be used when creating a folder as well to create a subfolder.
  • To add or remove parents for an exiting file, use the addParents and removeParents query parameters by calling PATCH https://www.googleapis.com/drive/v3/files/${fileId}

Files

  • When creating a batch of files, you can preallocate up to 1,000 UUIDs for use in create requests by calling GET https://www.googleapis.com/drive/v3/files/generateIds?count=${count}&space=drive This does not work when copying files.
  • All you need is the fileId to copy a file. It does not matter whether or not the document was created by a user of the destination Google Apps domain.

Sharing and permissions

  • When copying files, you can blow out the default visibility setting set by the Google Apps administrator using an optional query parameter ?ignoreDefaultVisibility=true.
  • When sharing you can disable notification e-mails by: ?sendNotificationEmail=false. Important: you cannot disable notification e-mails when transferring ownership.
  • To transfer ownership, use the optional query parameter ?transferOwnership=true

Code snippets

// PHP: Unofficial, extracts the fileId from a Google Drive/Docs URL
function getFileIdFromUrl($url) {
    preg_match('/(?P<fileId>[-\w]{25,})/', $url, $matches);
    return $matches['fileId'];
}
// JavaScript: Unofficial, extracts the fileId from a Google Drive/Docs URL
function getFileIdFromUrl(url) {
     return url.match(/[-\w]{25,}/);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment