我希望探索Google Admin SDK目录API。是否有快速入门指南或教程。 我看过文档有java和python的快速入门指南,但不是.Net。 我将非常感谢你的帮助。
答案 0 :(得分:0)
第一步是拥有一个具有域范围授权机构的服务帐户。 以下链接显示了如何操作 https://developers.google.com/admin-sdk/directory/v1/guides/delegation
它说要将服务帐户添加到"管理第三方OAuth客户端访问"在高级设置,但我有"管理OAuth客户端访问"也适用
String serviceAccountEmail = "......@developer.gserviceaccount.com";
X509Certificate2 certificate = new X509Certificate2(@"C:\key.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[]
{
DirectoryService.Scope.AdminDirectoryUser
},
User = "admin@domain.com"
}.FromCertificate(certificate));
var ser = new DirectoryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Get it to work",
});
User newuserbody = new User();
UserName newusername = new UserName();
newuserbody.PrimaryEmail = "jack@domain.com";
newusername.GivenName = "jack";
newusername.FamilyName = "black";
newuserbody.Name = newusername;
newuserbody.Password = "password";
User results = ser.Users.Insert(newuserbody).Execute();