一种仅在Google教室API python上使用未归档教室的方法

问题描述 投票:0回答:1

现在,我编写的脚本可以显示我已注册的所有课程。

courselist = []
    results = service.courses().list(pageSize=100).execute()
    courses = results.get('courses', [])

courses将返回我曾经注册的每门课程。我想知道是否有一种方法可以只获取当前正在注册的教室,而排除已存档的教室。

我曾尝试更改pageSize,但这仅更改了存储的课程数量。

python api google-classroom
1个回答
0
投票

您可以使用courseState请求参数,该参数将允许您根据其状态选择要检索的课程。这是使用Python的方式:

# Call the Classroom API
    results = service.courses().list(
        pageSize=10,
        # List with the course's states
        courseStates= ["ACTIVE"] # Another Ex: ["ACTIVE", "ARCHIVED"]
        ).execute()
    courses = results.get('courses', [])

    if not courses:
        print('No courses found.')
    else:
        print('Courses:')
        for course in courses:
            print(course['name'] + ": " + course['courseState'])

您也可以使用Try this API直接在API端点中对其进行测试。

© www.soinside.com 2019 - 2024. All rights reserved.