【问题标题】:Gsuite Classroom Api failing to add students and teachersGsuite Classroom Api 无法添加学生和教师
【发布时间】:2020-08-31 07:31:15
【问题描述】:

我正在使用我的域实现谷歌的课堂 API。正如documentation 所建议的那样,我正在创建一门课程。我创建了一个服务帐户并为该帐户分配了必要的范围,并且我使用管理员帐户作为委托帐户。该文件指出管理员可以直接创建课程,我的课程创建系统正在运行。它还说管理员可以直接添加教师和学生。当我尝试将学生或教师添加到课程中时,它会引发错误Request had insufficient authentication scopes,但我从link 中获得了正确的课堂范围。 我错过了什么吗?任何建议将不胜感激。

service_credentials = ServiceAccountCredentials.from_p12_keyfile('aServiceAccount.iam.gserviceaccount.com', 
'*.p12', 'notasecret',
scopes=['https://www.googleapis.com/auth/admin.directory.user',
'https://www.googleapis.com/auth/classroom.courses', 
'https://www.googleapis.com/auth/calendar'])
credentials = service_credentials.create_delegated(
            'anAdmin@domain')
class_service = build('classroom', 'v1',
                              credentials=credentials)
directory_service = build('admin', 'directory_v1',
                                  credentials=credentials)
calendar_service = build('calendar', 'v3',
                                 credentials=credentials)
course = {
            'name': 'This is dummy course',
            'section': 'dummy section',
            'descriptionHeading': 'Dummy course',
            'courseState': 'ACTIVE',
            'ownerId': 'anAdmin@domain' # also in the teachers group
        }
response = class_service.courses().create(body=course).execute()
course_id = response.get('id')
course_code = response.get('enrollmentCode')
teacher = {'userId': 'anotherUserFromTeachersGroup@domain'}
class_service.courses().teachers().create(courseId=course_id,body=teacher).execute()
        # error : Request had insufficient authentication scopes
student = {'userId': 'user@domain'}
class_service.courses().students().create(
            courseId=course_id, enrollmentCode=course_code, body=student).execute()
        # error : Request had insufficient authentication scopes

【问题讨论】:

    标签: python google-oauth google-classroom scopes


    【解决方案1】:

    您必须确保https://www.googleapis.com/auth/classroom.rosters 此范围存在于您的域范围委托和请求范围中。 Link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      相关资源
      最近更新 更多