我已经有了使用Google管理员目录添加用户的工作功能:
string password = Random_Password();
User newuserbody = new User();
UserName newusername = new UserName();
UserOrganization newuserorg = new UserOrganization();
newusername.GivenName = GivenName;
newusername.FamilyName = FamilyName;
newuserbody.Name = newusername;
newuserorg.Department = Department;
newuserorg.CostCenter = Country;
newuserorg.Title = JobTitle;
newuserbody.Organizations = newuserorg;
newuserbody.PrimaryEmail = GivenName + "." + FamilyName + email_suffix;
//SET PASSWORD
newuserbody.Password = password;
service.Users.Insert(newuserbody).Execute();
此代码有效,但部门,成本中心和标题等详细信息不会保存在记录中。只有名字,姓氏,电子邮件和密码才有效。
以下是代码:
UserOrganization[] newuserorg = new UserOrganization[1];
newuserorg[0] = new UserOrganization();
newuserorg[0].Department = Department;
newuserorg[0].CostCenter = Country;
newuserorg[0].Title = JobTitle;
newuserbody.Organizations = newuserorg;
newuserbody.PrimaryEmail = GivenName + "." + FamilyName + email_suffix;
//SET PASSWORD
newuserbody.Password = password;
service.Users.Insert(newuserbody).Execute();
答案 0 :(得分:0)
你应该试试
List<UserOrganization> l = new List<UserOrganization> { newuserorg };
newuserbody.Organizations = l;