仅当文件公开共享时才允许下载 google 文档
Allowing to download a google doc only if the file is shared publicly
我知道在使用 OAuth 授权请求时,我们可以使用多个范围来请求用户的特定权限。我想请求下载 publicly 共享 link 文件的权限(用户实际上会提供这个 link)。
但是,列出的范围 here 不提供这样的选项。我不想获得所有文件的权限并吓到他们。
下面是我正在使用的代码。有任何想法吗?您认为是否有可能获得 public link 文件的许可?访问 link 共享可以用于此目的吗?
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;
}
oauth 使用 google 驱动器的方式是您请求访问用户的完整驱动器帐户。
DriveService.Scope.DriveFile
将授予对用户驱动器帐户的访问权限,但只能访问使用您的客户端打开或创建的文件。
drive.readonly 将授予您完全访问其完整驱动器帐户的权限,以阅读和下载文件。无法限制您只能访问一个目录或一组文件。全有或全无。
获得访问权限后,您可以搜索所需的文件,因为您现在可以访问他们的完整帐户。
我知道在使用 OAuth 授权请求时,我们可以使用多个范围来请求用户的特定权限。我想请求下载 publicly 共享 link 文件的权限(用户实际上会提供这个 link)。
但是,列出的范围 here 不提供这样的选项。我不想获得所有文件的权限并吓到他们。
下面是我正在使用的代码。有任何想法吗?您认为是否有可能获得 public link 文件的许可?访问 link 共享可以用于此目的吗?
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;
}
oauth 使用 google 驱动器的方式是您请求访问用户的完整驱动器帐户。
DriveService.Scope.DriveFile
将授予对用户驱动器帐户的访问权限,但只能访问使用您的客户端打开或创建的文件。
drive.readonly 将授予您完全访问其完整驱动器帐户的权限,以阅读和下载文件。无法限制您只能访问一个目录或一组文件。全有或全无。
获得访问权限后,您可以搜索所需的文件,因为您现在可以访问他们的完整帐户。