I managed to implement editor access to my file using the help found here: Drive.Permissions.create({ role: "writer", type: "user", emailAddress: destinataireEd1 }, fileId, { sendNotificationEmail: false })
I plan to eventually modify the permissions granted to users over time : I tried to modify the role by putting "reader"
but the authorization is unchanged (I suppose that the create
method only works on the first permission).
While digging, I saw that it was possible to add an expiration date for access to a file which would save me from having to restart my script on the desired change date.
Drive.Permissions.create({ role: "writer", type: "user", emailAddress: destinataireEd1,expirationTime:"2025-03-11T09:25:00Z" }, fileId, { sendNotificationEmail: false })
I tried to implement it but I get an error message :
GoogleJsonResponseException: API call to drive.permissions.create failed with error: Expiration dates cannot be set on this item
I think I must not be using this function correctly : what mistake did I make?
I managed to implement editor access to my file using the help found here: Drive.Permissions.create({ role: "writer", type: "user", emailAddress: destinataireEd1 }, fileId, { sendNotificationEmail: false })
I plan to eventually modify the permissions granted to users over time : I tried to modify the role by putting "reader"
but the authorization is unchanged (I suppose that the create
method only works on the first permission).
While digging, I saw that it was possible to add an expiration date for access to a file which would save me from having to restart my script on the desired change date.
Drive.Permissions.create({ role: "writer", type: "user", emailAddress: destinataireEd1,expirationTime:"2025-03-11T09:25:00Z" }, fileId, { sendNotificationEmail: false })
I tried to implement it but I get an error message :
GoogleJsonResponseException: API call to drive.permissions.create failed with error: Expiration dates cannot be set on this item
I think I must not be using this function correctly : what mistake did I make?
Share Improve this question asked Mar 11 at 9:22 NicolasNicolas 1456 bronze badges 5- Where in the documentation does it state that permissions have an experation Time? – Linda Lawton - DaImTo Commented Mar 11 at 9:53
- 1 @LindaLawton-DaImTo developers.google/drive/api/reference/rest/v3/permissions – Nicolas Commented Mar 11 at 9:56
- I was able to set an expiration date using Google Drive API, were you able to check if you are adhering to the rules for setting expiration date? – 4thAnd1 Commented Mar 11 at 11:12
- I successfully added an expiration date using a Workspace account but failed on a regular Gmail account – 4thAnd1 Commented Mar 11 at 11:26
- I don't think expiration dates are supported for @gmail accounts. You need an account that belongs to a Google Workspace domain. – doubleunary Commented Mar 11 at 11:55
2 Answers
Reset to default 3As written in the official blog, This feature is only available on certain paid Google workspace domain accounts.
Available to Google Business Standard, Business Plus, Enterprise Essentials, Enterprise Essentials Plus, Enterprise Standard, Enterprise Plus, Education Fundamentals, Education Standard, the Teaching and Learning Upgrade and Education Plus customers
Not available to Essentials Starter, Business Starter, Frontline Starter, Frontline Standard, and Nonprofits
Not available to users with personal Google Accounts
Setting expiration date on Drive API permissions
Upon experimenting using the Google API explorer can be found here I found out that it is working on Workspace account but not on personal Gmail account, more information can be found here
Sample Input
{
"role": "commenter",
"type": "user",
"emailAddress": "[email protected]",
"expirationTime": "2025-03-12T09:25:00Z"
}
Given this sample Input, I get this output with success code 200
Sample Output
{
"kind": "drive#permission",
"id": "00111498891935165396",
"type": "user",
"role": "commenter"
}
References:
Improved flow for expiring access controls in Google Drive
Drive API permission.create method