使用Google Apps Provisioning API将用户添加到组织单位和组

时间:2014-10-14 16:47:49

标签: c# .net google-api google-provisioning-api

我已在.Net中编码,使用Google Apps Provisioning API创建Google帐户。我成功创建了Google帐户,但我无法将用户添加到特定的组织单位和组。我已经实现了帐户创建的目标:

//Creating Google Account

 AppsService appService = new AppsService("Mydomain", "AdminUsername", "AdminPassword");

         try
                {

                var account = appService.CreateUser(googleEmail, FirstName.Text, LastName.Text, password);

                }

                catch (Exception ex)
                {
                    ResultsLabel.Text += "<br />Can't create this Google Account";
                }

添加用户后,它会在Google的主域“用户”下创建。但我必须将该用户放入他们所属的组织单位,在我的情况下,我需要将用户置于“员工”组织单位。我不确定applicationName的含义,我只是使用项目解决方案名称,或者我在这里没有使用正确的名称? applicatinName是什么意思,我应该使用什么?我在以下代码中使用CustomerID作为“GoogleCustomerId”,这些代码是我从Google获取的域名代码。我已经完成了这样的编码,这对于将用户添加到组织单元不起作用:

//Adding User to Organization Unit


                OrganizationService service = new OrganizationService("mydomain", "applicationName");

                service.setUserCredentials("AdminUsername", "AdminPassword");

                service.UpdateOrganizationUser("GoogleCustomerId", Email.Text, "Staff", "Users"); 

我使用上面的代码将此例外添加到组织单位:

Google.GData.Client.GDataRequestException was unhandled by user code
  HResult=-2146233088
  Message=Execution of request failed: https://apps-apis.google.com/a/feeds/orguser/2.0/C090ll5hh/Test@domain.com
  Source=Google.GData.Client
  ResponseString=<?xml version="1.0" encoding="UTF-8"?>
<AppsForYourDomainErrors>
  <error errorCode="1801" invalidInput="" reason="InvalidValue" />
</AppsForYourDomainErrors>

以下是我将代码添加到Group的代码,但它也无效,我需要将用户添加到staff@mydomain.com组:

//Adding User to Group


   service.Groups.AddMemberToGroup("staff@mydomain.com", username);

请问这个想法吗?

由于

2 个答案:

答案 0 :(得分:1)

经过进一步的研究和更改代码,添加到组织单位和组现在正在运作。我必须把&#34; /&#34; for&#34; String oldOrgUnitPath&#34;因为它是最初添加用户的最高组织单位。

//将用户添加到组织单位

            OrganizationService service = new OrganizationService("mydomain", "applicationName");

            service.setUserCredentials("AdminUsername", "AdminPassword");

            service.UpdateOrganizationUser("GoogleCustomerId", Email.Text, "Staff", "/"); 

要添加到小组工作,我必须在代码中进行此更改。我们不应该将@ domain.com与组名一起使用,并切换电子邮件ID和组名的位置。

//Adding User to Group

   service.Groups.AddMemberToGroup(Email.Text, "Staff");

由于

答案 1 :(得分:0)

关于Google,此API即将于2015年4月底停止运作。

自去年以来,我遇到过这个API的一些问题,我决定改为使用“新”API:https://developers.google.com/admin-sdk/directory/

即使您现在解决了这个问题,如果您希望将来应用程序顺利运行,我建议您检查新的API。

祝你好运!