I think you get the idea there are a lot of possibilities for us with Google drive. My plans are to show you how to most of these work.
Fivepart Tutorial Series
- Google Drive API with C# .net – Authentication
- Google Drive API with C# .net – Files – Files, directories, search
- Google Drive API with C# .net – Upload, update, patch, delete, trash
- Google Drive API with C# .net – Download
- Google Drive API with C# .net – File Permissions
- Google Drive API with C# .net – Sample project
Restringing your application.
Like with most of the Google APIs you need to be authenticated in order to connect to them. To do that you must first register your application on Google Developer console. Under APIs be sure to enable the Google Drive API and Google Drive SDK, as always don’t forget to add a product name and email address on the consent screen form.
Make sure your project is at least set to .net 4.0.
Add the following NuGet Package
This tutorial assumes that you have already read the tutorial about Google Drive API with C# .net – Authentication. I will not be going into how to create a valid Drive service if you haven’t created one already please go read that tutorial then come back here.
Google Drive File Permissions
File permissions with in Google drive are quite simply permission for a file, to be specific they are a users permissions to a file.
Tip: Remember in Google Drive a directory or a folder is also a file, so file permissions also relates to permissions to a folder on Google drive
When you upload a file to Google drive the owner of the file is the account that did the uploading. This can cause some problems if you have a service account uploading to a folder on your personal Google Drive, you wont have permissions to it. To solve this problem we insert for our self to the permission on the file after we have uploaded it.
If you remember from the file upload tutorial, after your file is inserted to Google Drive it returns a file resource with in the file resource you can find the file id for the new file that was uploaded. you can use that to call the above method
InsertPermission(service, fileId, "email@example.com", "user", "owner");
You should now have owner access to the file.
I am just thinking out loud here but if the service account in question has access to the folder, it would be smart to have the service account to check the folder and see who has access to the folder and then add permissions to the new file to match the file that was just uploaded. That is probably up to the developer working on the project.
When a file is first inserted / uploaded to Google drive the owner of the file is the account that did the uploading. With C# we can programmatic grant people permissions to files or folders on Google drive using the Google Drive API. On Google drive permissions relates back to who has access to a file or folder.
It is also possible to update or patch permissions on a file in Google Drive let me know if you would like me to extend this tutorial to include update and patch.