0

我正在尝试通过其 SDK 从谷歌驱动器获取文档列表。我使用服务帐户完成身份验证,并将范围设置为具有完全权限的https://www.googleapis.com/auth/drive 。

但是,尽管我的谷歌驱动器中有测试文件,但响应包含一个空项目列表。

        AuthorizationServerDescription desc = GoogleAuthenticationServer.Description;
        X509Certificate2 key = new X509Certificate2(m_file, "notasecret", X509KeyStorageFlags.Exportable);

        string scope = Google.Apis.Drive.v2.DriveService.Scopes.Drive.ToString().ToLower();
        AssertionFlowClient client = new AssertionFlowClient(desc, key) { ServiceAccountId = m_email, Scope = "https://www.googleapis.com/auth/" + scope };

        OAuth2Authenticator<AssertionFlowClient> auth = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);


        DriveService service = new DriveService(auth);

        FilesResource.ListRequest request = service.Files.List();
        request.Q = "";
        Stream dataStream = request.FetchAsStream();
        StreamReader reader = new StreamReader(dataStream);
        string responseFromServer = reader.ReadToEnd();
4

1 回答 1

2

查看 Nivco 对Google Drive SDK 的回答:从 Drive 返回的空文件数组,了解有关您的问题的更多详细信息。

您基本上是在服务帐户的云端硬盘中列出文件,而不是您的。您需要做的是为您尝试模拟的域的用户设置电子邮件,查看 Google Drive SDK 文档以获取说明和示例代码,说明如何执行此操作:

https://developers.google.com/drive/delegation

于 2012-11-23T07:45:32.830 回答