【问题标题】:Adding User to Organization Unit and Group using Google Apps Provisioning API使用 Google Apps Provisioning API 将用户添加到组织单位和组
【发布时间】:2014-10-14 16:47:49
【问题描述】:

我已在 .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 是什么意思,我应该使用什么?在我从 Google 为我们的域获得的以下代码中,我使用 CustomerID 作为“GoogleCustomerId”。我已经完成了这样的编码,这不适用于将用户添加到组织单位:

//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>

这是我将用户添加到组的代码,但它也不起作用,我需要将用户添加到 staff@mydomain.com 组:

//Adding User to Group


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

请问有这方面的想法吗?

谢谢

【问题讨论】:

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


    【解决方案1】:

    经过进一步研究并更改添加到组织单位和组的代码,现在正在工作。我必须为“String oldOrgUnitPath”添加“/”,因为它是最初添加用户的顶级组织单位。

    //向组织单元添加用户

                OrganizationService service = new OrganizationService("mydomain", "applicationName");
    
                service.setUserCredentials("AdminUsername", "AdminPassword");
    
                service.UpdateOrganizationUser("GoogleCustomerId", Email.Text, "Staff", "/"); 
    

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

    //Adding User to Group
    
       service.Groups.AddMemberToGroup(Email.Text, "Staff");
    

    谢谢

    【讨论】:

      【解决方案2】:

      关于 Google,此 API 将于 2015 年 4 月下旬停止工作。

      自去年以来,我在使用此 API 时遇到了一些问题,因此我决定改用“新”API:https://developers.google.com/admin-sdk/directory/

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

      祝你好运!

      【讨论】:

      • 感谢 VicTheMagician 的建议。我应该很快看一下,但是SDK的实现如何?和 Google Apps Provisioning API 一样吗?
      • 它们在实现上存在一些差异。在新版本中,您必须通过 Visual Studio 中的 NuGet 管理器添加所需的所有类。然后您可以在代码中引用它们(例如“使用 Google.Apis;”)。
      猜你喜欢
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-24
      • 2020-12-05
      相关资源
      最近更新 更多