This is part of GoCloudStorage and not part of the main GoJS library. Storage can be found in the GoJS kit under the `projects` folder. See the Storage intro page for more information.

### Hierarchy

- GoCloudStorage
  - GoGoogleDrive

Class for saving / loading GoJS Models to / from Google Drive. Uses the Google Drive V3 API by use of a Google Client API object. As with all GoCloudStorage subclasses (with the exception of GoLocalStorage, any page using GoDropBox must be served on a web server.

Note: Any page using GoGoogleDrive must include a script tag with src set to https://apis.google.com/js/api.js.

## Index

### Constructors

- constructor

### Properties

- gapiClient
- gapiPicker
- pickerApiKey
- scope

### Methods

- authorize
- checkFileExists
- createPicker
- getFile
- getUserInfo
- load
- loadWithUI
- remove
- removeWithUI
- save
- saveWithUI
- showUI

## Inherited Members

### Properties

- GoCloudStorage.className
- GoCloudStorage.clientId
- GoCloudStorage.currentDiagramFile
- GoCloudStorage.defaultModel
- GoCloudStorage.iconsRelativeDirectory
- GoCloudStorage.isAutoSaving
- GoCloudStorage.managedDiagrams
- GoCloudStorage.serviceName
- GoCloudStorage.ui

### Methods

- GoCloudStorage.create
- GoCloudStorage.hideUI

## Constructors

### constructor

- new GoGoogleDrive(managedDiagrams: Diagram | Diagram[], clientId: string, pickerApiKey: string, defaultModel?: string, iconsRelativeDirectory?: string): GoGoogleDrive

- #### Parameters

  - ##### managedDiagrams: Diagram | Diagram[]

    An array of GoJS Diagrams whose model(s) will be saved to / loaded from Google Drive. Can also be a single Diagram.

  - ##### clientId: string

    The client ID of the Google application linked with this instance of GoGoogleDrive (given in Google Developers Console after registering a Google app)

  - ##### pickerApiKey: string

    The Google Picker API key. Once obtained, it can be found in the Google Developers Console

  - ##### Optional defaultModel: string

    String representation of the default model data for new diagrams. If this is null, default new diagrams will be empty. Usually a value given by calling Model.toJson on a GoJS Diagram's Model.

  - ##### Optional iconsRelativeDirectory: string

    The directory path relative to the page in which this instance of GoGoogleDrive exists, in which the storage service brand icons can be found. The default value is "../goCloudStorageIcons/".

  #### Returns GoGoogleDrive

## Properties

### Read-only gapiClient: any

- Get Google API Client. The Google API Client is used in GoGoogleDrive to make many different requests to Google Drive, however, it can be used with other Google Libraries to achieve many purposes. To read more about what can be done with a Google API Client object, click here. gapiClient is set after a succesful authorization in authorize.

  gapiClient is really of type Object, not type any. However, the Google libraries are all written in JavaScript and do not provide d.ts files. As such, to avoid TypeScript compilation errors, both gapiClient and gapiPicker properties are declared as type any.

### Read-only gapiPicker: any

- Get Google Picker API Object. Used to show the Google filepicker when loading / deleting files, in the createPicker function. gapiPicker is set after a succesful authorization in authorize.

  gapiPicker is really of type Object, not type any. However, the Google libraries are all written in JavaScript and do not provide d.ts files. As such, to avoid TypeScript compilation errors, both gapiClient and gapiPicker properties are declared as type any.

### Read-only pickerApiKey: string

- Get the Google Picker API key associated with this instance of GoGoogleDrive. This is set with a parameter during construction. A Google Picker API key can be obtained by following the process detailed here, and it can be found in your Google Developers Console. The pickerApiKey is used only in createPicker.

### Read-only scope: string

- Get the scope for the application linked to this instance of GoGoogleDrive (via clientId). Scope tells the gapiClient what permissions it has in making requests. Read more on scope here. The default value is 'https://www.googleapis.com/auth/drive', set during construction. This can only be modified by changing the source code for GoGoogleDrive. As changing scope impacts gapiClient's permissions (and could break the usability of some or all functions of GoGoogleDrive), this is not recommended.

## Methods

### Override authorize

- authorize(refreshToken?: boolean): Promise<unknown>

- Check if there is a signed in user who has authorized the application connected to this instance of GoGoogleDrive (via clientId. If not, prompt user to sign into their Google Account and authorize the application. On successful authorization, set gapiClient and gapiPicker.

  #### Parameters

  - ##### refreshToken: boolean = false

    Whether to get a new token (change current Google User)(true) or attempt to fetch a token for the currently signed in Google User (false).

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a boolean stating whether authorization was succesful (true) or failed (false)

### Override checkFileExists

- checkFileExists(path: string): Promise<unknown>

- Check whether a file exists at a given path

  #### Parameters

  - ##### path: string

    A valid GoogleDrive file ID -- not a path. Named 'path' only to preserve system nomenclature

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a boolean stating whether a file exists at a given path

### createPicker

- createPicker(cb: Function): void

- Launch Google Picker, a filepicker UI used to graphically select files in Google Drive to load or delete. This is accomplished with gapiPicker, which is set after succesful authorization, so this function may only be called after a successful call to authorize.

  #### Parameters

  - ##### cb: Function

    Callback function that takes the chosen file from the picker as a parameter

  #### Returns void

### Override getFile

- getFile(path: string): Promise<unknown>

- Get the Google Drive file reference object at a given path. Fields include:

  - id: The Google Drive-given ID of the file at the provided path
  - name: The name of the file saved to Google Drive at the provided path
  - mimeType: For diagram files, this will always be `text/plain`
  - kind: This will usually be `drive#file`.

  Note: Name, ID, and path values are requisite for creating valid DiagramFiles. When creating a DiagramFile for a diagram saved to Google Drive, provide the same value for name and path properties.

  #### Parameters

  - ##### path: string

    A valid GoogleDrive file ID -- not a path. Named 'path' only to preserve system nomenclature

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a Google Drive file reference object at a given path

### Override getUserInfo

- getUserInfo(): Promise<unknown>

- Get information about the currently logged in Google user. Some fields of particular note include:

  - displayName
  - emailAdrdress
  - kind

  #### Returns Promise<unknown>

  Returns a Promise that resolves with information about the currently logged in Google user

### Override load

- load(path: string): Promise<unknown>

- Get the contents of a saved diagram from Google Drive using a given Google Drive file ID. No UI of any sort appears.

  #### Parameters

  - ##### path: string

    A valid GoogleDrive file ID -- not a path. Named 'path' only to preserve GoCloudStorage system nomenclature

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a DiagramFile representing the loaded file

### Override loadWithUI

- loadWithUI(): Promise<unknown>

- Load the contents of a saved diagram from Google Drive using the Google Picker (see gapiPicker and createPicker).

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a DiagramFile representing the loaded file

### Override remove

- remove(path: string): Promise<unknown>

- Delete a the diagram from a user's Google Drive with the given Google Drive file ID. No UI of any sort appears.

  #### Parameters

  - ##### path: string

    A valid GoogleDrive file ID -- not a path. Named 'path' only to preserve system nomenclature

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a DiagramFile representing the deleted file

### Override removeWithUI

- removeWithUI(): Promise<unknown>

- Delete a selected diagram from a user's Google Drive using the Google Picker (see gapiPicker and createPicker).

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a DiagramFile representing the deleted file

### Override save

- save(path?: string): Promise<unknown>

- Save managedDiagrams' model data to GoGoogleDrive. If path is supplied save to that path. If no path is supplied but currentDiagramFile has non-null, valid properties, update saved diagram file content at the path in GoGoogleDrive corresponding to currentDiagramFile.path with current managedDiagrams' model data. If no path is supplied and currentDiagramFile is null or has null properties, this calls saveWithUI.

  #### Parameters

  - ##### Optional path: string

    A name (not a path, not an id) to save this diagram file in Google Drive under. Named 'path' only to preserve system nomenclature

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a DiagramFile representing the saved file

### Override saveWithUI

- saveWithUI(): Promise<unknown>

- Save the current managedDiagrams's model data to the current Google user's Google Drive using the custom ui save prompt.

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a DiagramFile representing the saved file

### Override showUI

- showUI(): any

- Show the custom GoGoogleDrive save prompt; a div with an HTML input element that accepts a file name to save the current managedDiagrams data to in Google Drive.

  #### Returns any

  Returns a Promise that resolves (in save, load, or remove) with a DiagramFile representing the saved/loaded/deleted file

Copyright © 1998-2022 by Northwoods Software Corporation.