[英]Adding User to Organization Unit and Group using Google Directory API
[英]Adding User to Organization Unit and Group using Google Apps 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是什么意思,我应该使用什么? 在以下我从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);
请问对此有任何想法吗?
谢谢
经过进一步研究并更改了代码,现在正在为组织部门和组工作。 我必须在“ String oldOrgUnitPath”中输入“ /”,因为它是最初添加用户的最高组织单位。
//将用户添加到组织单位
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");
谢谢
对于Google,此API将于2015年4月下旬停止运行。
自去年以来,我在使用此API时遇到了一些问题,我决定改用“新” API: https : //developers.google.com/admin-sdk/directory/
即使您现在已经解决了此问题,如果您希望应用程序将来能够平稳运行,我还是建议您检查一下新的API。
祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.