有人拥有Google DirectoryService.Users.List().Execute()吗;以在C#/.NE

本文关键字:以在 NE Execute DirectoryService Google Users List 拥有 | 更新日期: 2023-09-27 18:24:14

我已经尝试在我的谷歌应用程序域中列出用户一段时间了。Python中没有问题,但在C#中,我得到一条错误消息:出现错误:Google.Apis.Requests.RequestError错误请求[400]错误[消息〔Bad Request〕位置〔-〕原因〔badRequest〕域〔global〕]

我不是任何类型的C#大师,但当我浏览Google.Apis.Admin.directory_v1.cs-文件时,我觉得UserResource ListRequest好像错了???它在文件的第7349-7352行找到。有人知道它是否还没有在API中实现吗?

编辑:我从为什么我认为Google.Apis.Admin.directory_v1.cs中的代码第7349-7352行是错误的(正如我所提到的-我不是C#大师):

守则:

 /// <summary>Retrieve either deleted users or all users in a domain (paginated)</summary>
    public virtual ListRequest List() {
        return new ListRequest(service);
}

为什么我觉得奇怪:

我可以看到在哪里将customerid或domain作为参数传递给这个请求,但在API资源管理器中需要它(否则我会在我的原始帖子中收到与上面相同的错误消息)。

编辑:我在文件中往下看了一点,我想第8904行及以后的行正在做我之前寻找的事情。我的坏!

但我仍然无法让我的代码工作?!?!?


我的代码不起作用:

static void Main(string[] args)
    {
        // Display the header and initialize the sample.
        CommandLine.EnableExceptionHandling();
        Console.WriteLine("List users in a google apps domain!");
        Console.WriteLine("by Jonas Bergstedt 2013");
        // Get the domainname
        Console.Write("Domain: ");
        string domain = Console.ReadLine();
        // Register the authenticator.
        var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description)
        {
            ClientIdentifier = <myClientId>,
            ClientSecret = <myClientSecret>",
        };
        var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
        // Create the service.
        var service = new DirectoryService(new BaseClientService.Initializer()
        {
            Authenticator = auth,
            ApplicationName = "List Users",
            ApiKey = <myApiKey>
        });
        // Trying to add the domain
        service.Users.List().Domain = domain;
        Users results = service.Users.List().Execute();
        foreach (User list in results.UsersValue)
        {
            Console.WriteLine("- " + list.Name);
        }
    }
    private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
    {
        // Get the auth URL:
        IAuthorizationState state = new AuthorizationState(new[] { DirectoryService.Scopes.AdminDirectoryUser.GetStringValue() });
        state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
        Uri authUri = arg.RequestUserAuthorization(state);
        // Request authorization from the user (by opening a browser window):
        Process.Start(authUri.ToString());
        Console.WriteLine();
        Console.Write("Authorization Code: ");
        string authCode = Console.ReadLine();
        // Retrieve the access token by using the authorization code:
        return arg.ProcessUserAuthorization(authCode, state);
    }
}

有人拥有Google DirectoryService.Users.List().Execute()吗;以在C#/.NE

ListRequest具有这些属性。看起来这些属性不是强制性的,所以它们不是构造函数的一部分。您可以执行以下操作:

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