0

I have done coding in .Net to create google account using Google Apps Provisioning API. I am successful in creating Google Account but I am not being able to add user to particular Organization Unit and Group. I have achieved the goal of account creation like this:

//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";
                }

After user is added, it gets created under main domain "Users" in Google. But I have to put that user into the Organization unit where they belong to, here in my case, I need to put the user into "Staff" Organization Unit. I am not sure what applicationName means, I am just using the project solution name or am I not using correct name here? What does applicatinName mean, and what should I use? I am using CustomerID as "GoogleCustomerId" in following code that I got from Google for our domain. I have done coding like this which doesn't work for adding user to Organization Unit:

//Adding User to Organization Unit


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

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

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

I get this exception with the above code to add user to Organization Unit:

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>

Here is my code to add user to Group but it is also not working, I need to add user to staff@mydomain.com group:

//Adding User to Group


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

Any idea on this one please?

Thanks

4

2 回答 2

1

经过进一步研究并更改添加到组织单位和组的代码现在正在工作。我必须为“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");

谢谢

于 2014-10-15T14:10:37.307 回答
0

关于谷歌,这个 API 将在 2015 年 4 月下旬停止工作。

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

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

祝你好运!

于 2014-10-21T11:38:13.413 回答