Google Drive API 1.4错误:发送直接消息或获取响应时出错

本文关键字:消息 获取 响应 出错 API Drive 错误 Google | 更新日期: 2023-09-27 18:22:42

我正在使用下面的一段代码来获取带有服务帐户的文件。

        var certificate = new X509Certificate2("D:''05-privatekey.p12", "notasecret", X509KeyStorageFlags.Exportable);
        var privateKey = certificate.Export(X509ContentType.Cert);
        var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
        {
            ServiceAccountId = "877564787679-glrhdp0gclc9mbj77qe4998dkc6mfj62@developer.gserviceaccount.com",
            Scope = DriveService.Scopes.Drive.GetStringValue(),
            ServiceAccountUser = "user1@05.mygbiz.com"
        };
        var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);
        DriveService service = new DriveService(new BaseClientService.Initializer()
        {
            Authenticator = auth,
            ApplicationName = "My APP",
        });
        FilesResource.ListRequest request = service.Files.List();
        FileList files = request.Execute();

这里Execute()api给出异常

发送直接消息或获取响应

编辑:项目基于上述设置@https://code.google.com/p/google-api-dotnet-client/wiki/Build

编辑2:我在CPanel中根据服务帐户进行了正确的设置

Google Drive API 1.4错误:发送直接消息或获取响应时出错

我也遇到了同样的问题。我最终使它发挥了作用;我做错了几件事。

  1. 我去了谷歌云控制台,重新生成并下载了我的密钥文件。转到API&auth->已注册的应用程序
  2. 我在provider对象中放入的唯一属性是.ServiceAccountId.Scope
  3. 我不得不用实际的作用域替换Scope,而不使用枚举值(这只是一个问题,因为我使用的是VB)。我在Fusion Tables中工作,因为VB.NET不使用GetStringValue()枚举函数,所以范围仅呈现为"Fusiontables"。现在我使用"https://www.googleapis.com/auth/fusiontables"。请转到此处查看有效作用域的列表
  4. 对于ServiceAccountId,我使用了带有"@"的服务帐户"电子邮件地址:"(12345@developer.gserviceaccount.com),而不是他们在控制台中标记为"客户端ID:"的那个(12345.apps.googleusercontent.com)

希望这能帮助其他人。