几天来,我一直在寻找这方面的信息.我相信我已经为访问正确设置了与API相关的所有内容,但我一直收到这个错误: 服务管理员引发了异常.
HttpStatusCode is BadRequest.
Google.Apis.Requests.RequestError
Bad Request [400]
Errors [
Message[Bad Request] Location[ - ] Reason[badRequest] Domain[global]
]
Google.GoogleApiException: The service admin has thrown an exception. HttpStatusCode is BadRequest. Bad Request
at Google.Apis.Requests.ClientServiceRequest`1.ParseResponse(HttpResponseMessage response)
at Google.Apis.Requests.ClientServiceRequest`1.ExecuteAsync(CancellationToken cancellationToken)
at Google.Apis.Requests.ClientServiceRequest`1.ExecuteAsync()
我运行代码的方法:
string[] googleScopes = {DirectoryService.Scope.AdminDirectoryUser};
public async Task connectToGoogle()
{
try
{
GoogleCredential credential = GoogleCredential.FromFile(googleTokenPath).CreateScoped(googleScopes);//.CreateWithUser(googleAdminEmail);
var service = new DirectoryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "TestAPIProject"
});
var request = service.Users.List();
request.Customer = "test.example.com";
request.Domain = "test.example.com";
var result = await request.ExecuteAsync();
Console.WriteLine(result);
}
catch (Exception e)
{
System.Console.WriteLine(e);
}
}
据我所知,JSON令牌在这方面是正确的.我认为问题出在客户或域名上,但我已经try 了很多不同的 Select ,仍然得到了Bad Request.
我正在使用Google Workspace服务帐户发送请求.确保使用该令牌,而不是OAuth令牌.