Google drive api 无法使用GoogleDrive API列出文件

Google drive api 无法使用GoogleDrive API列出文件,google-drive-api,Google Drive Api,我正试图通过谷歌硬盘的SDK从谷歌硬盘上获取一份文档列表。我使用服务帐户来完成身份验证,并设置具有完全权限的范围 但是,响应包含一个空项目列表,尽管我的google驱动器中确实有测试文件 AuthorizationServerDescription desc = GoogleAuthenticationServer.Description; X509Certificate2 key = new X509Certificate2(m_file, "notasecre

我正试图通过谷歌硬盘的SDK从谷歌硬盘上获取一份文档列表。我使用服务帐户来完成身份验证,并设置具有完全权限的范围

但是,响应包含一个空项目列表,尽管我的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();
AuthorizationServerDescription desc=GoogleAuthenticationServer.Description;
X509Certificate2 key=新的X509Certificate2(m_文件,“notasecret”,X509keystargeFlags.Exportable);
string scope=Google.api.Drive.v2.DriveService.Scopes.Drive.ToString().ToLower();
AssertionFlowClient客户端=新建AssertionFlowClient(desc,key){ServiceAccountId=m_电子邮件,作用域=”https://www.googleapis.com/auth/“+范围};
OAuth2Authenticator auth=新的OAuth2Authenticator(客户端,AssertionFlowClient.GetState);
DriveService=新的DriveService(身份验证);
fileResource.ListRequest请求=service.Files.List();
请求。Q=“”;
Stream dataStream=request.FetchAsStream();
StreamReader=新的StreamReader(数据流);
字符串responseFromServer=reader.ReadToEnd();
有关您的问题的更多详细信息,请查看Nivco对的答复

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


谢谢克劳迪奥。我是Google Drive SDK的新手。似乎我必须是某个特定域的管理员才能设置我无法设置的委派。我想做的是设置一个服务,将我的文档从Google Drive下载到本地数据库,不应该有GUI来获得身份验证。有什么建议吗?您需要至少通过OAuth流一次才能批准应用程序,但之后您可以永久存储刷新令牌,并使用它生成新的访问令牌,而无需用户交互: