尝试执行获取GROUPS的请求时,Google Directory API返回“403 - 权限不足”错误

时间:2021-05-09 15:20:27

Actual error message:

实际错误消息:

Unhandled Exception: Google.GoogleApiException: Google.Apis.Requests.RequestError Insufficient Permission [403] Errors [ Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global] ]

未处理的例外:Google.GoogleApiException:Google.Apis.Requests.RequestError权限不足[403]错误[消息[权限不足]位置[ - ]原因[insufficientPermissions]域[global]]

It only throws this error when I try to access GROUPS. I can obtain the users just fine. Here is my code:

它只在我尝试访问GROUPS时抛出此错误。我可以很好地获得用户。这是我的代码:

private static readonly int maxResultsReturned = 500;
private static readonly string ApplicationName = "Directory API .NET Quickstart";
private static readonly string[] Scopes = { DirectoryService.Scope.AdminDirectoryUserReadonly,
                                            DirectoryService.Scope.AdminDirectoryGroupReadonly
};

public static void getGroups()
{
    var service = setUpService();

    // Define parameters of request.
    var request = service.Groups.List();
    request.Customer = "my_customer";
    request.MaxResults = maxResultsReturned;

    IList<Group> groups = request.Execute().GroupsValue; //Error thrown here

    foreach (Group groupItem in groups)
    {
        Console.WriteLine("{0}", groupItem);
    }
}

Error is thrown when calling IList<Group> groups = request.Execute().GroupsValue;

调用IList groups = request.Execute()时会引发错误.GroupsValue;

Is there something I'm missing? I tried including all of the scopes that DirectoryService holds, but still getting the same error.

有什么我想念的吗?我尝试包含DirectoryService保留的所有范围,但仍然得到相同的错误。

Anyone have any input?

有人有任何意见吗?

1 个解决方案

#1


0  

In addition to having the right scope the user you are impersonating (if using a service account) or running the script as must also have the rights set in the admin console. This may be the case, it was for me a couple of days ago.

除了拥有正确的范围之外,您模拟的用户(如果使用服务帐户)或运行脚本,还必须在管理控制台中设置权限。情况可能就是这样,几天前我就是这样。

#1


0  

In addition to having the right scope the user you are impersonating (if using a service account) or running the script as must also have the rights set in the admin console. This may be the case, it was for me a couple of days ago.

除了拥有正确的范围之外,您模拟的用户(如果使用服务帐户)或运行脚本,还必须在管理控制台中设置权限。情况可能就是这样,几天前我就是这样。