使用Google apis for .Net时遇到一些问题。 调用服务时,由于某种原因调用失败,将抛出GoogleApiException。 HttpStatusCode在异常中始终为0。我可以从Message中解析状态代码,但这当然不是一个好的解决方案。
我正在使用NuGet的最新二进制文件(1.5.0.28972)
我也遇到了使ExponentialBackoff算法工作的问题,我认为它与这个问题有关。
下面是复制行为的som代码。
const string ServiceAccount = "000000000000@developer.gserviceaccount.com";
const string KeyFile = @"C:\privatekey.p12";
const string KeyPass = "notasecret";
const string ApplicationName = "Test";
const string User = "admin@some-domain.com"; // this is the user you wish to act for
static void Main(string[] args)
{
var certificate = new X509Certificate2(KeyFile, KeyPass,
X509KeyStorageFlags.Exportable);
var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
{
ServiceAccountId = ServiceAccount,
Scope = DirectoryService.Scopes.AdminDirectoryUser.GetStringValue(),
ServiceAccountUser = User,
};
var authenticator = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);
var initializer = new BaseClientService.Initializer
{
Authenticator = authenticator,
DefaultExponentialBackOffPolicy = BaseClientService.ExponentialBackOffPolicy.UnsuccessfulResponse503
};
var service = new DirectoryService(initializer);
// This will throw a GoogleApiException the the HttpStatusCode is 0 (Should be 409)
var user = service.Users.Get("none-existing-user@some-domain.com").Execute();
}
此致 / Tor的