我正在尝试通过其SDK从google驱动器获取文档列表。我使用服务帐户完成身份验证,并将范围设置为具有完全权限的https://www.googleapis.com/auth/drive。
但是,虽然我的google驱动器中有测试文件,但响应中包含一个空项目列表。
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();
答案 0 :(得分:2)
检查Nivco对Google Drive SDK: Empty array of files returned from Drive的回答,了解有关您的问题的详细信息。
您基本上列出了服务帐户的云端硬盘中的文件而不是您的文件。您需要做的是为您尝试模拟的域的用户设置电子邮件,查看Google Drive SDK文档以获取相关说明以及示例代码示例: