0

I am using Google Admin SDK API to provision users/group in Google using Stand alone C# code and all operations including create user, update user, create group, add member, get member ,search user etc are working perfectly fine now I am trying to invoke Group Setting API to update few of the group settings however I am getting a

Login Required exception (401).

I have added group settings in service account scope and added the same Group Settings in security settings in Google Admin console & enabled Group Settings in Developer console Scope: GroupssettingsService.Scope.AppsGroupsSettings Admin Console Security Settings : https://www.googleapis.com/auth/apps.groups.settings

I am not sure what is wrong here, rest all APIs are working fine and I tried the same from API explorer and that is also working fine.

//Connect Google Snippet

public static DirectoryService fnConnectGoogle()
{
            Console.WriteLine("Connect to Google API");
            Console.WriteLine("=====================");

            String serviceAccountEmail = "xyz@developer.gserviceaccount.com";
            var certificate = new X509Certificate2(@"D:\CECV\Google\GoogleAppsProvisioning.p12", "notasecret", X509KeyStorageFlags.Exportable);

            ServiceAccountCredential credential = new ServiceAccountCredential(
            new ServiceAccountCredential.Initializer(serviceAccountEmail)
            {
                User = "test@mydomain.com",
                Scopes = new[] { DirectoryService.Scope.AdminDirectoryUser, DirectoryService.Scope.AdminDirectoryGroup,
                    GroupssettingsService.Scope.AppsGroupsSettings}
            }.FromCertificate(certificate));


            var dirservice = new DirectoryService(new BaseClientService.Initializer()
            {enter code here
                HttpClientInitializer = credential,
                ApplicationName = "GoogleAppsProvisioning"
            });
            return dirservice;
}

//Update Group Settings


public static void fnUpdateGroupSetting(DirectoryService dirService)
{
            GroupssettingsService groupSetting = new GroupssettingsService();
            //   Groups group = new Groups();
            Google.Apis.Groupssettings.v1.Data.Groups group = new Google.Apis.Groupssettings.v1.Data.Groups();

             group.AllowWebPosting = "true";
            var g = groupSetting.Groups.Update(group, "testgroupprovisioning-code-1@vic.catholic.edu.au").Execute();
            Console.WriteLine("Group Settings updated successfully"+g.AllowWebPosting );
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • This might be helpful for you: http://stackoverflow.com/questions/13776174/google-group-settings-api-enabled-for-service-accounts – KRR Apr 24 '15 at 00:01
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Apr 24 '15 at 01:12

1 Answers1

0

Have you logged in with test@mydomain.com to activate it? I was having the same problem, only until I realized the service account is trying to act as the user, if user is not activated, it might not work. APIs other than GroupSettings don't seem to have the issue though.

zhywu
  • 1,012
  • 1
  • 12
  • 26