如何创建一个使用drive.file仅访问特别请求的文件的Google API应用程序?

问题描述 投票:0回答:1

我正在编写一个 C# 桌面应用程序,其工作的一部分是在用户创建并提供 URL 的现有 Google 表格中添加/编辑单元格。在开发过程中,我使用了更加开放的 Sheets.Files 和 Drive.Files 范围,允许对任何地方的所有内容进行读/写访问。

我现在尝试使用 Drive.File 范围来限制应用程序仅访问我们将与之交互的特定工作表文件。然而,我真的很难理解如何作为身份验证流程的一部分,请求用户访问写入文件。

之前我使用的是:

        public async Task AuthGoogleSheets(CancellationToken cancellationToken)
        {
            using (var stream = new FileStream(CredentialsFilePath, FileMode.Open, FileAccess.Read))
            {
                _googleCreds = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.FromStream(stream).Secrets,
                    new[] { SheetsService.Scope.Spreadsheets },
                    "user",
                    cancellationToken,
                    new FileDataStore(AuthTokenFilePath));

                await _googleCreds.RefreshTokenAsync(cancellationToken);
            }

            // Create Google Sheets service.
            sheetsService = new SheetsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = _googleCreds,
                ApplicationName = "myappname",
            });
        }

我本来希望简单地在工作表 URL 中添加

LoginHint
就能完成这项工作,但没有帮助。我需要使用 DriveService 发送权限请求电子邮件吗?这对我来说听起来不对。

c# google-api google-drive-api google-api-dotnet-client
1个回答
0
投票

Drive.File 范围使您可以访问仅由您的应用程序创建的文件。

所有其他范围都允许您访问用户的完整驱动器帐户。

例如,drive.readonly 将为您提供对用户 Google Drive 帐户的完全只读访问权限。

不使用Drive.File就无法限制它

© www.soinside.com 2019 - 2024. All rights reserved.