ren*_*kre 5 c# google-api google-drive-api google-oauth google-api-dotnet-client
我知道,在使用OAuth授权请求时,我们可以使用多个范围来请求用户的特定权限。我想请求允许下载带有公共共享链接的文件(用户实际上将提供此链接)。
但是,此处列出的范围不提供此类选项。我不想获得所有文件的许可并吓scar他们。
下面是我正在使用的代码。有任何想法吗?您认为有可能获得具有公共链接的文件的许可吗?可以使用共享链接的访问权限吗?
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;
}
Run Code Online (Sandbox Code Playgroud)
oauth 与 Google Drive 配合使用的方式是您请求访问用户的完整驱动器帐户。
DriveService.范围.DriveFile
将授予对用户驱动器帐户的访问权限,但只能访问使用您的客户端打开或创建的文件。
drive.readonly 将为您提供对其完整驱动器帐户的完全访问权限,以读取和下载文件。无法限制您仅访问一个目录或一组文件。要么全有,要么全无。
一旦您获得访问权限,您就可以搜索所需的文件,因为您现在可以访问其完整帐户。
| 归档时间: |
|
| 查看次数: |
74 次 |
| 最近记录: |