C# Google Dotnet API-管理SDK组-获取错误请求错误
只是试着细读一下Google Dotnet API管理SDK 当我试图检索所有组的列表时,出现了一些错误。我仍然对文档感到困惑(使用哪些方法或函数等) 我现在拥有的代码:C# Google Dotnet API-管理SDK组-获取错误请求错误,c#,google-api-dotnet-client,C#,Google Api Dotnet Client,只是试着细读一下Google Dotnet API管理SDK 当我试图检索所有组的列表时,出现了一些错误。我仍然对文档感到困惑(使用哪些方法或函数等) 我现在拥有的代码: using System; using System.IO; using System.Threading; using Google.Apis.Auth.OAuth2; using Google.Apis.Services; using Google.Apis.Util.Store; using Google.Apis.
using System;
using System.IO;
using System.Threading;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using Google.Apis.Admin.Directory.directory_v1;
using Google.Apis.Admin.Directory.directory_v1.Data;
namespace GoogleConsoleApp
{
class Program
{
static void Main(string[] args)
{
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { DirectoryService.Scope.AdminDirectoryGroup, DirectoryService.Scope.AdminDirectoryGroupReadonly },
"user", CancellationToken.None, new FileDataStore("Tasks.Auth.Store")).Result;
}
var dirSvc = new DirectoryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Groups API Sample",
});
Groups myGroups = dirSvc.Groups.List().Execute();
这句话几乎是错误的:
Unhandled Exception: Google.GoogleApiException: Google.Apis.Requests.RequestError
Bad Request [400]
Errors: [Message [Bad Request] Location [ - ] Reason[badRequest] Domain[global]]
我已经在开发人员控制台中启用了必要的API
任何有关这方面的帮助都将不胜感激
更新:
我也尝试过这种方法(根据):
但是我仍然得到相同的错误。您需要显式设置请求的域。错误在于,如果您像其他类型的请求一样将域留空,则假定它只搜索全局域。在本例中,它将尝试搜索客户组,该组也是空白的。从报纸上的一张便条上 检索时:
- 子域的所有组-将域参数与域名一起使用
- 帐户的所有组-将customer参数与my_customer或帐户的customerId值一起使用。作为帐目 管理员,使用字符串my_customer表示您帐户的 客户ID。如果您是经销商,访问转售客户的 帐户,使用转售帐户的customerId。对于customerId值 在中使用帐户的主域名检索中的所有用户 域操作的请求。结果响应具有customerId 价值观
- 使用域和客户参数-API返回域的所有组
- 不使用域和客户参数-API返回与my_customer关联的帐户的所有组。这是 发出API请求的管理员的帐户客户ID。
GroupsResource.ListRequest groupRequest = _service.Groups.List();
groupRequest.Domain = "YourDomain";
Groups domainGroups = groupRequest.Execute();
不起作用并将抛出完全相同错误的示例:
GroupsResource.ListRequest groupRequest = _service.Groups.List();
Groups domainGroups = groupRequest.Execute();
1.能否添加请求和响应的fiddler输出?2.另外,请您检查一下Google API Explorer()是否能正常工作。请注意,您必须确保服务器/计算机执行请求的时间与Google在其服务器上的时间相同。
GroupsResource.ListRequest groupRequest = _service.Groups.List();
Groups domainGroups = groupRequest.Execute();