Google Drive SDK

Share Files

Google Drive apps can manage permissions and sharing settings of files. The Permissions feed provides apps the ability to read, update, and delete permissions for users, Google groups, Google Apps domains, and the public.

In addition to managing permissions through the API, apps can display a standard Google Drive sharing dialog to let users share files. To implement this, you'll need to add some simple JavaScript to your application code as described below in Launching the Google Drive sharing dialog in your app.

Contents

Types, roles and values: how the permissions work

Lists of permissions (referred to as ACLs in the now obsolete Documents List API) are available for each file and folder in Drive. Each permission specifies a type, role, and value, permitting a level of access to a file or folder. Type, role, and value work together to limit the access appropriately. The type limits access to a set of users. The value specifies which user of the type can have access. Finally, the role gives these users the ability to do something to the file, like read it. When combined, these properties define a complete permission.

Roles

Each permission in the Google Drive API is defined for a role. A role defines what users can do with a file. The following table describes what operations users in each role can perform.

Permitted operation owner reader writer commenter
Read the properties (e.g. title, description) of the file
Read the content of the file
Read the properties (e.g. title) of the folder
Read the list of files or folders in the folder
Modify the properties of the file
Modify the content of the file
Modify the properties of the folder
Add files or folders to the folder
Delete the file
Delete the folder
Add comments to the Google Doc

Types and values

Every permission of a file or folder has a type. The type is the scope of the permission, and determines which users have a role. Every permission also has a value, which specifies the relevant users of the type. For example, a permission with a type of domain may have a value of thecompany.com, indicating that the permission grants the given role to all users in the Google Apps domain thecompany.com. The list shows what types and values are possible.

Type Write-only? Possible values
user Yes Email address of a user. Write this value when adding a new permission. Once the permission exists, identify which user this permission refers to using the id field of the permission. Example: joe@thecompany.com
group Yes Email address of a Google Group. Write this value when adding a new permission. Once the permission exists, identify which group this permission refers to using the id field of the permission. Example: admins@thecompany.com
domain No Domain name of Google Apps domain. Read or write this value when you need to get or set the domain of a permission. Example: thecompany.com
anyone No The value of an anyone permission is always an empty string. Any value set for an anyone permission is discarded.

IDs and names

Each permission also has id and name fields.

The id is always the unique identifier of the value of the permission. The following is a list of potential IDs for each type of permission.

Type Possible id values
user String identifier of this specific user. The user is not necessarily yet a Google user (e.g. if a file or folder is shared with an email address that does not yet have an associated Google account). Example: 1111459233037698895607
group String identifier of this specific Google Group. Example: 1111459233037698895607
domain String domain name. Example: thecompany.com
anyone Always the string anyone.

The name is always the "pretty" name of the value of the permission. The following is a list of potential names for each type of permission.

Type Possible name values
user User's full name, as defined for their Google account. Example: Joe Smith
group Name of the Google Group. Example: The Company Administrators
domain String domain name. Example: thecompany.com
anyone Always the string Anyone.

Retrieving, adding, and manipulating permissions

Full examples on how to work with permissions are provided in the reference guide.

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('<YOUR_APP_ID>');
        s.setItemIds(["<FILE_ID>"]);
    }
    window.onload = function() {
        gapi.load('drive-share', init);
    }
</script>
</head>

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 showSharingSettings() is called, the script handles displaying the dialog (which is modal).

For the dialog to work as expected, all of the following must be true:

  • The user is signed in to Google
  • The user has installed your app
  • The URL of the page that launches the dialog must have the same origin as the Open URL registered for the app.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.