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 );
}