I am trying to create my first console app using Google\'s Directory API for .Net.
I have a code based in a Google\'s sample. It shows me a couple of errors, one
have to have a service account with Perform Google Apps Domain-Wide Delegation of Authority as defined in
https://developers.google.com/admin-sdk/directory/v1/guides/delegation
it say to add it in the "Manage third party OAuth Client access" i had "Manage OAuth Client access "
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();