我正在使用下面的代码来获取带有服务帐户的文件。
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 中根据服务帐户进行了适当的设置