我期待探索 Google Admin SDK Directory API。是否有可用的快速入门指南或教程。我查看了文档,其中有 java 和 python 的快速入门指南,但没有 .Net。我的帮助将不胜感激。
问问题
582 次
1 回答
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();
于 2014-08-07T09:58:33.663 回答