gpt4 book ai didi

c# - Google 管理员目录用户错误

转载 作者:太空狗 更新时间:2023-10-29 20:20:54 24 4
gpt4 key购买 nike

使用 Google API .NET 客户端 v1.3.0-beta。

我创建了一个控制台应用程序来从 Service Accounts 的示例代码中测试 Google Admin Directory 的基础知识。这应该会给我域​​中所有电子邮件地址的计数。

using System;
using System.Collections.Generic;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Admin.directory_v1;
using Google.Apis.Admin.directory_v1.Data;
using System.Security.Cryptography.X509Certificates;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Services;
using Google.Apis.Util;

namespace ConsoleApplication1
{
class Program
{
private const string SERVICE_ACCOUNT_EMAIL = "012345678901@developer.gserviceaccount.com";
private const string SERVICE_ACCOUNT_ID = "012345678901.apps.googleusercontent.com";
private const string SERVICE_ACCOUNT_PKCS12_FILE_PATH = @"C:\ConsoleApplication1\randomlyassigned-privatekey.p12";

static void Main(string[] args)
{
X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable);
var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
{
ServiceAccountId = SERVICE_ACCOUNT_EMAIL,
Scope = AdminService.Scopes.AdminDirectoryUser.GetStringValue()
};

var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);
var service = new AdminService(new BaseClientService.Initializer()
{
Authenticator = auth
});

UsersResource.ListRequest listReq = service.Users.List();
Users us = listReq.Fetch();
Console.WriteLine(us.UsersValue.Count);
}
}
}

当我尝试 Fetch() 用户列表时出现以下错误:

Google.Apis.Requests.RequestError
Bad Request [400]
Errors [
Message[Bad Request] Location[ - ] Reason[badRequest] Domain[global]
]

知道我在这里做错了什么吗?

最佳答案

我得到了一些帮助来解决这个问题。要列出用户,您必须将域或客户作为列表请求的参数传递。使用客户或域。

@peleyal 帮助我找到了如何做到这一点:

var listReq = service.Users.List();
listReq.Customer = "CUSTOMER_HERE";
listReq.Domain = "DOMAIN_HERE";
Users results = listReq.Execute();

关于c# - Google 管理员目录用户错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17304233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com