Launching the Google Drive sharing dialog in your app

To let users share Drive files directly from your app, you can use a JavaScript-based Google Drive sharing dialog. Your app can launch the dialog from a "Share" button or whatever mechanism works best for your app's design. To enable the Drive sharing dialog, you'll need to add the dialog script, and add a launch button or mechanism in your UI.

Add the dialog script

Add this script to launching page:

<head>
...
<script type="text/javascript" src="https://apis.google.com/js/api.js"></script>
<script type="text/javascript">
    init = function() {
        s = new gapi.drive.share.ShareClient();
        s.setOAuthToken('<OAUTH_TOKEN>');
        s.setItemIds(['<FILE_ID>']);
    }
    window.onload = function() {
        gapi.load('drive-share', init);
    }
</script>
</head>

The placeholder <OAUTH_TOKEN> should be replaced with the authorized user's OAuth2 access token. Replace <FILE_ID> with the id of the file to share.

Add a launch button

In the appropriate place in the body of your UI, add a line like the following:

<button onclick="s.showSettingsDialog()">Share</button>

When users click this button and showSettingsDialog() is called, the script handles displaying the dialog (which is modal).

For the dialog to work as expected, the user must be currently signed in to the Google account matching the identity of the oauth token.

Send feedback about...

Drive REST API v2
Drive REST API v2