尝试将成员添加到Google组时获取“权限不足[403]”(目录服务API,.Net)

时间:2015-09-08 23:04:18

标签: c# .net google-admin-sdk google-directory-api google-groups-api

尝试使用.Net中的Google Directory Services API将成员添加到群组时,继续获得不足的权限[403]。

*我们设置了Google域名 *用户xxxxx是域名管理员 *我以用户xxxxx身份登录管理控制台并创建了一个服务帐户。

*为该服务帐户获取关联/生成的Google ClientID,并为其提供以下范围:

https://www.googleapis.com/auth/admin.directory.group
https://www.googleapis.com/auth/admin.directory.group.member
https://www.googleapis.com/auth/admin.directory.user

*该群组是我们域中的已创建群组。这是一个有效的团体。我可以手动添加/删除用户。
*用户xxxxx是该组的所有者和成员 *我要添加的用户是我们域中的有效帐户 * xxxxx帐户和服务帐户都已设置并正常工作,以便我可以使用Google Directory Services API以编程方式在我们的域上创建用户,而不会出现任何问题。 (即,已启用Admin SDK等)。

我用来尝试将用户添加到群组的代码片段非常简单:

GroupsResource.GetRequest grGet = m_service.Groups.Get("TestGroup@OurGoogleDomain.com");//Existing group
string szGroupID = grGet.GroupKey;
Member userMember = new Member();    
userMember.Email = "u.test1923@OurGoogleDomain.com";//Existing user
userMember.Role = "MEMBER";
m_service.Members.Insert(userMember, szGroupID).Execute();

我在代码中遗漏了什么吗?我是否需要设置一些专门针对Google网上论坛设置但却不知道的设置?任何帮助,将不胜感激!谢谢!

1 个答案:

答案 0 :(得分:0)

我使用以下服务声明测试了您的代码,并且运行顺利。

String serviceAccountEmail = "Enter your service account email";
        var certificate = new X509Certificate2("GoogleDirectoryManager-xxxxxxxxxx.p12", "Enter your Key", X509KeyStorageFlags.Exportable);

        ServiceAccountCredential credential = new ServiceAccountCredential(
        new ServiceAccountCredential.Initializer(serviceAccountEmail)
        {
            User = "Enter an Admin Email for the Domain",

            Scopes = new[] { DirectoryService.Scope.AdminDirectoryUser, DirectoryService.Scope.AdminDirectoryGroupMember }
        }.FromCertificate(certificate));

您可能需要指定与您在域API客户端访问权限上授权的Google API服务帐户关联的正确范围和/或服务帐户。

相关问题