I know that when authorizing requests with OAuth, we can use several scopes to ask for a specific permission from the user. I want to ask for the permission for downloading files with publicly shared links (the user will actually provide this link).
However, the scopes listed here do not provide such an option. I do not want to get the permission for all the files and scare them.
Below is the code I am using. Any ideas? Do you think is it possible to get permission for the files with public links? Having access to the link shared can be utilized for this purpose?
private string[] Scopes = { DriveService.Scope.DriveFile};
private DriveService GetDriveServiceInstance()
{
UserCredential credential;
using (var stream = new FileStream("Services/credentials.json", FileMode.Open, FileAccess.Read))
{
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
BaseClientService.Initializer bcs = new BaseClientService.Initializer();
bcs.HttpClientInitializer = credential;
bcs.ApplicationName = "synergy";
DriveService service = new DriveService(bcs);
return service;
}
The way oauth works with google drive is that you are requesting access to a users full drive account.
DriveService.Scope.DriveFile
Will give access to a users drive account but only access to the files which where opened or created with your client.
drive.readonly will give you full access to their full drive account to read and download files. There is no way to limit your access to only a directory, or only a group of files. its all or nothing.
Once you have access you can then search for the files you want as you now have access to their full account.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With