我正在使用Google Admin SDK API使用独立的C#代码在Google中配置用户/群组,所有操作包括创建用户,更新用户,创建群组,添加成员,获取成员,搜索用户等,现在我的工作完全正常我试图调用组设置API来更新一些组设置但是我得到了一个
登录必需的例外(401)。
我在服务帐户范围中添加了组设置,并在Google管理控制台和安全设备的安全设置中添加了相同的组设置。在Developer Console中启用了Group Settings 范围: GroupssettingsService.Scope.AppsGroupsSettings 管理控制台安全设置: https://www.googleapis.com/auth/apps.groups.settings
我不确定这里有什么问题,所有API都运行正常,我在API资源管理器中尝试了相同的操作,并且工作正常。
//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 );
}
答案 0 :(得分:0)
您是否已使用 test@mydomain.com 登录以激活它?我遇到了同样的问题,直到我意识到服务帐户试图充当用户,如果用户未被激活,它可能无法正常工作。但GroupSettings以外的API似乎没有问题。