google-classroom - 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 控制台创建。我添加了自定义管理员角色。
解决方案
我发现教室课程的所有者必须是教室教师组的成员。(如果帐号不是超级管理员)
使用尚未成为教师的帐户,教室 api 会出错。并且成为老师后(手动登录,创建课堂课程),课堂api成功。
因此,在创建课程之前,我将该帐户加入了教室教师组。
谢谢你。
推荐阅读
- javascript - 如何在 Angular 8 的 FileReader 中从 2 个不同的 HTML 输入中获取 2 个文件?
- bash - Bash 4.4 无法自动完成“更多”但不是“更少”或“cd”的环境变量
- python - 从服务调用 Python 子进程失败
- javascript - 纯 Javascript 上的全屏弹出窗口 - 无框架
- javascript - 无法循环传递给组件的数组
- laravel - 如何检查刀片模板中是否需要字段?
- groovy - 将时间戳附加到groovy中的文件名
- php - PHP - 为什么 floor() 给我另一个 sams 计算结果
- python - 访问 127.0.0.1:8000 时,它无法正常工作,我收到无法访问此站点的消息
- android - 在 2 个改造实例之间保持会话