最初是由我在this SO thread 发送的。
此任务的相应 Classroom API 参考是 here。
看起来即使启用 高级 Google 服务...,您也只会添加以下 OAuth 范围 -
您可以通过导航到 文件 > 项目属性 > 范围来查看这些内容。
但是,当您从文档链接尝试 API 时,在 Credentials > Google OAuth 2.0 选项卡下,它显示了另外 4 个完全不同的 OAuth 范围;如下-
您需要在您的 Apps 脚本清单文件中手动添加所有 8 个。为此,导航至查看并检查显示清单文件。您需要在此处添加此代码,可能在依赖项下方 -
"oauthScopes": [
"https://www.googleapis.com/auth/classroom.courses",
"https://www.googleapis.com/auth/classroom.coursework.me.readonly",
"https://www.googleapis.com/auth/classroom.profile.emails",
"https://www.googleapis.com/auth/classroom.profile.photos",
"https://www.googleapis.com/auth/classroom.rosters",
"https://www.googleapis.com/auth/classroom.coursework.me",
"https://www.googleapis.com/auth/classroom.coursework.me.readonly",
"https://www.googleapis.com/auth/classroom.coursework.students",
"https://www.googleapis.com/auth/classroom.coursework.students.readonly"
],
注意 1:仅添加较新的 4 不会起作用,因为脚本会假定只有这些而不是原始的 5 在您的脚本第一次运行时自动填充。
注意2:空白行只是为了区分自动生成的范围与您需要手动添加的范围(它是多余的)。
我的appsscript.json 文件如下所示;你的可能会有所不同 -
{
"timeZone": "Asia/Kolkata",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Classroom",
"serviceId": "classroom",
"version": "v1"
}]
},
"oauthScopes": [
"https://www.googleapis.com/auth/classroom.courses",
"https://www.googleapis.com/auth/classroom.coursework.me.readonly",
"https://www.googleapis.com/auth/classroom.profile.emails",
"https://www.googleapis.com/auth/classroom.profile.photos",
"https://www.googleapis.com/auth/classroom.rosters",
"https://www.googleapis.com/auth/classroom.coursework.me",
"https://www.googleapis.com/auth/classroom.coursework.me.readonly",
"https://www.googleapis.com/auth/classroom.coursework.students",
"https://www.googleapis.com/auth/classroom.coursework.students.readonly"
],
"exceptionLogging": "STACKDRIVER"
}