Skip to main content

Google Drive

The google-drive module lets editors search and import files from a linked Google Drive account through Brightspot's federated search, and can keep an imported file in sync with later changes in Drive.

Dependencies

Depends on db-http, Google's Drive API v3 client (com.google.apis:google-api-services-drive), and Google's OAuth2 client libraries for per-user account linking.

Installation

<!-- Requires Brightspot 5.0 or later. -->
<dependency>
<groupId>com.brightspot.dbhttp</groupId>
<artifactId>google-drive</artifactId>
<version>1.0.0</version>
</dependency>

API reference

com.psddev.google.drive.GoogleDriveDatabase

Extends HttpDatabase. Excludes folders from both keyword search and the default (no-keyword) browse listing, so an editor can never select a folder as if it were a file. Keyword search uses Drive's full-text query syntax; the no-keyword browse listing supports sorting by name or last-modified date (sorting isn't available together with a keyword, per Google's API).

com.psddev.google.drive.GoogleDriveFile

Extends GoogleExternalItem.

FieldTypeDescription
nameStringThe file name.
fileIdStringThe Google Drive file Id.
descriptionStringThe file description.
originalFilenameStringThe original uploaded file name.
sizeLongThe file size in bytes.
ownedByMeBooleanWhether the linked account owns the file.
createdTimeDateWhen the file was created in Drive.
modifiedByMeBooleanWhether the linked account was the last to modify the file.
modifiedByMeTimeDateWhen the linked account last modified the file.
modifiedTimeDateWhen the file was last modified in Drive.
lastModifiedByStringWho last modified the file in Drive.
fileExtensionStringThe file extension.
fullFileExtensionStringThe full (possibly multi-part) file extension.
kindStringThe Drive API resource kind.
mimeTypeStringThe file's MIME type.
fileTypeStringA human-readable file type label derived from mimeType.
trashedBooleanWhether the file is in the Drive trash.
trashedTimeDateWhen the file was trashed.
trashingUserStringWho trashed the file.
webContentLinkStringA direct download link.
webViewLinkStringA link to view the file in Drive.
ownersList<String>The file's owners in Drive.

Configuration

The OAuth2 client Id and secret are stored on GoogleDriveSettings, a Modification<CmsTool> shown under Site Settings > Integrations > Google. Each editor additionally links their own Google account before they can search Google Drive.

note

Registering the OAuth redirect URI in the Google Developer Console is required before linking works. The redirect URI is https://<your-brightspot-host>/googleDriveAuth.

Extending the plugin

The module doesn't ship a content type for imported files. To let editors create a local content record from search results, define a content type and extend UpdatableExternalItemConverter<GoogleDriveFile, T>, implementing both convert (to create the record on import) and update (to apply changes from Drive to an existing record).

Implementing update also enables sync: GoogleDriveSyncable compares the source file's modified time against the time it was last imported, and if the record's content type implements GoogleDriveSyncable, an editor can re-import it—producing a draft with the differences if the record is published, or updating it directly otherwise.

Was this page helpful?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.