首页 > 解决方案 > 403 当前用户在为 Google 课堂 api (.Net) 创建课程时无法创建课程 [禁止]

问题描述

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

错误 [ 消息 [@UserCannotCreateCourse 当前用户无法创建课程。] 位置 [ - ] 原因 [禁止] 域 [全局] ]

我的代码在下面给出

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/classroom/courses ./auth/classroom/rosters (等等)

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

标签: google-classroom

解决方案


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

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

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

谢谢你。


推荐阅读