Last active
May 10, 2019 08:55
-
-
Save LindaLawton/3103a7f6ac8ef0a1b38b to your computer and use it in GitHub Desktop.
How to add permissions to a file or folder on Google drive in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Insert a new permission. | |
/// </summary> | |
/// <param name="service">Drive API service instance.</param> | |
/// <param name="fileId">ID of the file to insert permission for.</param> | |
/// <param name="who"> | |
/// User or group e-mail address, domain name or null for "default" type. | |
/// </param> | |
/// <param name="type">The value "user", "group", "domain" or "default".</param> | |
/// <param name="role">The value "owner", "writer" or "reader".</param> | |
/// <returns>The inserted permission, null is returned if an API error occurred</returns> | |
public static Permission InsertPermission(DriveService service, String fileId, String who,String type, String role) { | |
Permission newPermission = new Permission(); | |
newPermission.Value = value; | |
newPermission.Type = type; | |
newPermission.Role = role; | |
try { | |
return service.Permissions.Insert(newPermission, fileId).Execute(); | |
} catch (Exception e) { | |
Console.WriteLine("An error occurred: " + e.Message); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is just returning null.