如何获取 Google Classroom API 的课程 ID

清昌

我正在尝试使用Google Classroom API,我已经阅读了他们的文档,并且课程 ID 基本上用于所有内容,但他们从未解释在哪里可以找到课程的课程 ID。

当您创建课程时,该函数似乎也会返回课程 ID,但我想知道是否可以获取已存在课程的课程 ID。

肉桂

如文档的快速入门页面 ( https://developers.google.com/classroom/quickstart/python ) 所示,您可以运行一段代码来列出用户可以使用其凭据访问的前 10 门课程。然后,您可以print(course['id'])在迭代课程时添加一条语句,以打印您检索到的课程的 ID。python示例如下所示

from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/classroom.courses.readonly']

def main():
    """Shows basic usage of the Classroom API.
    Prints the names of the first 10 courses the user has access to.
    """
    creds = None
    # The file token.pickle stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('classroom', 'v1', credentials=creds)

    # Call the Classroom API
    results = service.courses().list(pageSize=10).execute()
    courses = results.get('courses', [])

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

if __name__ == '__main__':
    main()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用classrrom api获取特定课程的老师

Google Classroom API-权限被拒绝

Google Classroom API-可以修改用户ID吗?

Google Classroom API快速集成

使用Google Classroom API的C#阅读学生名单

Google Classroom Python也提供返修课程资料

没有注册代码的Google Classroom API列出的课程?

是否可以使用Google Classroom API从课程标题更改图像?

为什么在Google Classroom API上创建课程不起作用?

Google Classroom API:使用Google App脚本获取课程创建者的电子邮件

如何使用Google Classroom API访问课堂课程流

如何从Google Calendar API获取事件ID?

如何使用API获取Google Plus页面ID

如何从Google Analytics API获取广告的唯一ID

API以获取课程中的课程类别

如何在仅具有课程ID的成绩表中获取每个课程的名称?

您如何使用Google Forms API以编程方式获取Google Forms列表(带有ID)?

Moodle通过Api获取课程信息和所有课程

EDX课程API:获取EDX课程列表

如何从moodle Web 服务API 获取课程价格

Google Classroom API 创建课程链接

用于列出所有 Google Classroom 课程并将其放入 Google 电子表格的 Google Apps 脚本

Google 日历 api 无法获取颜色 ID

Google Classroom API 创建材料

Google Classroom API - 如何在检索课程列表时格式化 setFields 参数

访问创建者帐户或使用超级管理员是在 Google Classroom API 中收集课程数据的唯一方法吗?

如何在 Google Classroom 中使用 Topic Name 获取 Topic ID?

Google Classroom API 访问要求

如何在不使用 Google API 的情况下制作 Google Classroom 机器人?