Add the "Share" button

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:

<script type="text/javascript" src=""></script>
<script type="text/javascript">
    init = function() {
        s = new;
    window.onload = function() {
        gapi.load('drive-share', init);

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
Need help? Visit our support page.