Google Admin Directory API: Add User Employee Details

拟墨画扇 提交于 2019-12-23 02:42:09

问题


I already have a working function for adding user using Google Admin Directory:

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();

This code works, but the details such as Department, Cost Center, and Title doesn't save on the record. Only First, Last name, email and password works.


Solved

Here's the code:

        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();

回答1:


you should try

List<UserOrganization> l = new List<UserOrganization> { newuserorg };
newuserbody.Organizations = l;


来源:https://stackoverflow.com/questions/30502824/google-admin-directory-api-add-user-employee-details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!