【问题标题】:A way to only use non archived classrooms on google classrooms API python一种仅在谷歌教室 API python 上使用非归档教室的方法
【发布时间】:2020-03-19 21:37:44
【问题描述】:

现在我编写的脚本可以显示我曾经注册过的每门课程。

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

courses 将返回我曾经注册过的每一门课程。我想知道是否有办法只获取我目前注册的教室,而排除存档的教室。

我已尝试更改 pageSize,但这只会更改存储的课程数量。

【问题讨论】:

    标签: python api google-classroom


    【解决方案1】:

    您可以使用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 端点中对其进行测试。

    【讨论】:

    • 非常感谢!我试图使用 IF 语句从 courses 中删除课程,但没有成功。
    • 很高兴我的回答能帮到你!
    猜你喜欢
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多