【问题标题】:403 Current user cannot create courses [forbidden] while creating a course for Google classroom api (.Net)403 当前用户在为 Google 课堂 api (.Net) 创建课程时无法创建课程 [禁止]
【发布时间】:2021-07-14 07:33:24
【问题描述】:

我创建了一个 VisualStudio (C#) 项目,使用 google 课堂 API。 使用超级管理员,它可以创建课程,但使用委派管理员,它会返回错误。 我使用了委派的管理员。为什么会返回该错误?

错误 [ Message[@UserCannotCreateCourse 当前用户无法创建课程。] Location[-] Reason[forbidden] Domain[global] ]

我的代码如下所示

string[] Scopes = {ClassroomService.Scope.ClassroomCourses};

UserCredential credential;
using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
{
    string credPath = "token.json";
    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets,
        Scopes,
        "user",
        CancellationToken.None,
        new FileDataStore(credPath, true)).Result;
    Console.WriteLine("Credential file saved to: " + credPath);
}

var service = new ClassroomService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "Classroom test"
});

var body = new Course()
{
    Name = "MyFirstClass",
    OwnerId = "me"
};
var course = service.Courses.Create(body).Execute();

“credentials.json”文件来自我的谷歌云平台项目。 我的项目已经过验证。 ./auth/教室/课程 ./auth/教室/名册 (等等)

委派管理员由 Google 控制台创建。 我添加了自定义管理员角色。

【问题讨论】:

  • 您是如何执行域范围委派的?你能给我们更多的了解吗?
  • 我在 Google Cloud Platform 中创建了一个项目,并验证了我的应用程序。当我将 google 帐户(从超级管理员更改为委托管理员)进行身份验证时发生此错误。
  • 您是否在执行域范围委派后更新了代码中的凭据? “当我更改身份验证的谷歌帐户时发生此错误”到底是什么意思?您在代码中的哪个位置对服务帐户执行身份验证?
  • 如果域范围的委派意味着由谷歌控制台(安全 - API 控制)进行授权,我就这样做了。当我使用 Google Workspace for Education 帐户登录时发生此错误。今天我发现使用 Google 工作区帐户(不适用于教育)创建课程的课堂 api 成功。

标签: google-classroom


【解决方案1】:

我发现教室课程的所有者必须是教室教师组的成员。 (如果帐号不是超级管理员)

使用尚未成为教师的帐户,教室 api 出现错误。 并且成为老师后(手动登录,创建课堂课程),课堂api成功。

因此,在创建课程之前,我将该帐户加入了教室教师组。

谢谢。

【讨论】:

  • 这行得通,当业务组被激活时会发生这种情况,奇怪的是我有另一个帐户,该帐户不在组中并且可以正常工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-25
相关资源
最近更新 更多