This is a good start but I was getting errors related to the Certificate:
"At least one client secret (Installed or Web) should be set"
The problem is that the code provided has you using UserCredentials and some funky streaming stuff. The credentials can be read from the stream like this into a Google Credentials object.
GoogleCredential credential = null;
using (var stream = new FileStream(credentialsFileName, FileMode.Open, FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream);
credential = credential.CreateScoped(scopes);
}
You then use that Google Credentials along with your application name to get the service:
// Create Drive API service.
return new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = applicationName,
});
Now after that fix, the original example works. I am assuming that since the article was written this has changed and the article has not been updated. After applying this I do get the list of files from the article.
If you want to do more than read from the drive then you will need to change your scope.
Scopes
A scope is what determines what the calls made using the service can do. In general there are 2 scopes: Read-Only and Full Access. There are other scopes you can use as well.If you want to do more than read from the drive then you will need to change your scope.
string[] ReadOnlyScope = { DriveService.Scope.DriveReadonly }; // Read Only
public static string[] FullAccessScope = { DriveService.Scope.Drive }; // Full Access
Permissions
It took a while to find how permissions work but I did find an article on Managing Shares that does go into it. It boils down to 2 types of permission: user and domain. A user permission assigns an individual user access. A domain permission assigns a domain access eg. "sitecore.net". A permission has a role. The article describes the roles as "reader" and "writer". This is a text string so possibly there are other roles as well.
Now personally, I have got the user permissions to work but when I try domain permissions I get an error. If you have successfully got domain working can you provide an example or take a look at the functions on GitHub for Domain Permission to see if there is something I am doing wrong? I am passing "readwatchcreate.com" as domain.
Now personally, I have got the user permissions to work but when I try domain permissions I get an error. If you have successfully got domain working can you provide an example or take a look at the functions on GitHub for Domain Permission to see if there is something I am doing wrong? I am passing "readwatchcreate.com" as domain.
GitHub Libraries
I have created a GoogleAPIs public repository on GitHub. There are 2 folders. One for those still using .NET Framework which will not be updated and a DotCore folder with the new version built on .NET Standard and .NET Core. This includes a base library that has the code to connect to the API, a library that wraps some Google Drive functions to help you, and a unit test console app that will show sample calls and do positive and negative testing of the library. As I continue my learning of Google APIs, I will be adding more libraries for GoogleSheet and other API sections.