Send feedback
Display the sharing dialog
Stay organized with collections
Save and categorize content based on your preferences.
To allow users to share Drive files directly from your app, you can use the
Google Drive sharing dialog. This modal dialog is invoked
from your app to allow sharing of items on Drive. Figure 1 shows the Google Docs
Share button and the resulting sharing dialog.
Figure 1. Share button and dialog.
To enable the Drive sharing dialog, add the dialog script and a launch button
or other launching mechanism to your UI.
Add the dialog script
To create an instance of the sharing dialog, add the following script to your
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 >
Where:
In your UI, add a line of code similar to the following:
<button onclick="s.showSettingsDialog()">Share</button>
This code calls the showSettingsDialog()
function when the Share button is
clicked.
Note: For the dialog to work as expected, third-party party cookies must be
enabled and the user must be currently signed in to the Google account matching
the identity of the oauth token.
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-03 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
Need to tell us more?
{"lastModified": "Last updated 2024-09-03 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-03 UTC."],[],[]]