To display your app in Google Drive when a user creates or opens a file, you must first configure a Drive UI integration. Configuration is also required to list your app in the Google Workspace Marketplace.
Request the drive.install scopeYou must request the https://www.googleapis.com/auth/drive.install scope to integrate with the Drive UI. When requesting this scope, users see a dialog similar to this: For more information about scopes you can request for Drive apps, and how to request them, see What scope or scopes does my app need? Note: If your app is published to the Google Workspace Marketplace, users and domain administrators can search for and install the app directly from the Google Workspace Marketplace.The state parameterBy default, a state parameter is appended to the Open and New URL to pass data from the Drive UI to your app. This parameter contains a JSON-encoded string containing template variables with data about the request to your app. The variables included depend on the type of URL used (Open URL or New URL): Template variable Description Applicable to which URL type? {ids} A comma-separated list of file IDs that are being opened. Open URL {exportIds} A comma-separated list of file IDs that are being exported (used only when opening native Google documents). Open URL {resourceKeys} A JSON dictionary of file IDs mapped to their respective resource keys. Open URL {folderId} The id of the parent folder. New URL {folderResourceKey} The resource key of the parent folder. New URL {userId} The profile ID that uniquely identifies the user. Open URL and New URL {action} The action being performed. This value is open when using an Open URL or create when using a New URL. Open URL and New URLThe state parameter is URL-encoded, so your app must handle the escape characters and parse it as JSON. Apps can detect the create value in the state parameter to verify that this is a request to create a new file. Example state information for a New URL (in JSON notation)The state information for a New URL is: Example state information for an Open URL (in JSON notation)The state information for an Open URL is: { "ids": ["0Bz0bd"], "resourceKeys":{"0Bz0bd":"AAshj23Ad1"}, "action":"open", "userId":"103354693083460731603" }The IDs and resource keys are used to fetch file metadata and download file content. Once your app has the file ID and an access token, it app can check permissions, fetch the file metadata, and download the file content as described in the reference documentation for files.get. Note: All apps, including apps opening files from shortcuts and third-party shortcuts, should call files.get to check the user's permissions for a document. Apps should warn read-only users when they are opening a file they cannot edit or save (instead of letting them spend time editing, and then giving an error on save).Next stepsAn installed app needs to be able to handle create and open actions launched from the Drive UI. See Handle a New URL or Handle a Open URL to learn more. |