ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

gogcli 实战指南:用 `gog classroom students get` 查询 Google Classroom 学生花名册

gogcli 实战指南:用 `gog classroom students get` 查询 Google Classroom 学生花名册 gogcli 实战指南用gog classroom students get查询 Google Classroom 学生花名册【免费下载链接】gogcliGoogle Workspace in your terminal.项目地址: https://gitcode.com/GitHub_Trending/gogcl/gogcligog classroom students get是 gogcliGoogle Workspace in your terminal中用于查询指定课程内单个学生注册记录的只读命令对应 Google Classroom API 的courses.students.get端点。本文将围绕该命令的用法、位置参数、输出格式、全局 Flags 及底层 Go 源码实现展开帮助你快速掌握通过命令行检索学生信息用户 ID、邮箱、姓名、作业文件夹的完整方案。命令概览与语法该命令在 gogcli 的命令树中位于classroom - students - get由 internal/cmd/classroom.go 中的ClassroomStudentsCmd结构体注册支持单数别名student。根据文档 gog-classroom-students-get.md其完整语法为gog classroom (class) students (student) get (info,show) courseId userId其中括号内为可互换的别名classroom/classstudents/studentget/info/show因此以下写法完全等价gog classroom students get 1234567890 aliceexample.com gog class student info 1234567890 aliceexample.com gog class students show 1234567890 aliceexample.com两个位置参数均为必填位置参数说明courseId课程 ID 或课程别名源码中定义为name:courseId见 classroom_rosters.gouserId学生用户 ID 或邮箱地址从源码看ClassroomStudentsGetCmd.Run 会先对两个参数执行strings.TrimSpace去除首尾空白随后逐一校验任一参数为空时立即返回usage(empty courseId)或usage(empty userId)错误避免向 API 发出无效请求。输出格式文本模式与 JSON 模式命令执行成功后的输出由--json/--machine-j标志决定两种模式的行为差异直接体现在源码中。默认文本模式不带--json时命令按行输出 TSV 风格的关键字段classroom_rosters.gouser_id 1234567890 email aliceexample.com name Alice Zhang work_folder 1abcdefghijklmnopqrstuvwxyz各字段含义user_idGoogle Classroom 中的学生用户 IDemail通过profileEmail(student.Profile)读取UserProfile.EmailAddress见 classroom_helpers.goname通过profileName(student.Profile)读取优先取Name.FullName若为空则拼接GivenName与FamilyName见 classroom_helpers.gowork_folder条件输出只有当student.StudentWorkFolder ! nil时才打印该学生专属作业文件夹的 Drive 文件 ID可用于后续gog drive系列命令定位该学生的提交目录。JSON 模式使用-j/--json时输出包裹为带student键的结构化 JSONclassroom_rosters.gogog classroom students get 1234567890 aliceexample.com --json{ student: { userId: 1234567890, profile: { id: ..., name: { givenName: Alice, familyName: Zhang, fullName: Alice Zhang }, emailAddress: aliceexample.com }, studentWorkFolder: { id: 1abcdefghijklmnopqrstuvwxyz } } }student对象即 Google Classroom API 的classroom.Student类型完整返回体。在 JSON 模式下还可叠加以下输出控制 Flags--results-only仅输出主结果丢弃nextPageToken等信封字段--select/--pick/--project按逗号分隔字段选择输出支持点路径例如--select student.userId,student.profile.emailAddress--wrap-untrusted将远程获取的文本字段包裹在外部不可信内容标记中便于 Agent 或下游程序识别数据来源边界。若需稳定可解析的纯文本输出可使用-p/--plain/--tsv输出无颜色、便于管道处理的 TSV。Flags 完整参考该命令继承 gogcli 的全局 Flags 体系完整列表如下来自文档 gog-classroom-students-get.mdFlagTypeDefaultHelp--access-tokenstringUse provided access token directly (bypasses stored refresh tokens; token expires in ~1h)-a--account--acctstringAccount email, alias, or auto for authenticated Google API commands--clientstringOAuth client name (selects stored credentials token bucket)--colorstringautoColor output: auto|always|never--disable-commandsstringComma-separated list of disabled commands; dot paths allowed-n--dry-run--dryrun--noop--previewboolDo not make changes; print intended actions and exit successfully--enable-commandsstringComma-separated list of enabled command prefixes; dot paths allowed (restricts CLI)--enable-commands-exactstringComma-separated list of exact enabled commands; dot paths allowed and parent commands do not enable children-y--force--assume-yes--yesboolSkip confirmations for destructive commands--gmail-no-sendboolfalseBlock Gmail send operations (agent safety)-h--helpkong.helpFlagShow context-sensitive help.--homestringOverride gogcli config/data/state/cache root (equivalent to GOG_HOME)-j--json--machineboolfalseOutput JSON to stdout (best for scripting)--no-input--non-interactive--noninteractiveboolNever prompt; fail instead (useful for CI)-p--plain--tsvboolfalseOutput stable, parseable text to stdout (TSV; no colors)--quota-projectstringGoogle Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC)--readonlyboolfalseBlock mutating API requests at runtime; auth add also requests read-only OAuth scopes--results-onlyboolIn JSON mode, emit only the primary result (drops envelope fields like nextPageToken)--select--pick--projectstringIn JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands.-v--verboseboolEnable verbose logging--versionkong.VersionFlagPrint version and exit--wrap-untrustedboolfalseIn JSON/raw output, wrap fetched text fields in external untrusted-content markers与查询实践密切相关的几个 Flags 说明--account-a/--acct指定认证账号可为邮箱、别名或auto。命令运行时会通过requireAccount(flags)解析账号并校验认证状态见 classroom_rosters.go。--readonly只读安全模式。students get本身是只读查询但在启用该模式的环境中如safety-profiles/readonly.yaml定义的 Agent 安全配置所有变更类命令会被拦截本命令可安全运行。--no-inputCI 场景推荐遇到需要交互确认的环节直接失败而非挂起等待输入。底层实现从 CLI 到 Google Classroom API调用链ClassroomStudentsGetCmd.Run的执行路径classroom_rosters.go为从ctx获取 UI 输出器requireAccount(flags)解析并校验账号去除参数空白并校验非空classroomService(ctx, account)获取已认证的*classroom.Service客户端调用svc.Courses.Students.Get(courseID, userID).Context(ctx).Do()完成 HTTP 请求按输出模式格式化结果。其中classroomService定义于 runtime_services.go经由运行时服务注册表返回 Google Classroom 客户端Classroom 服务本身在 googleauth/service.go 中注册为ServiceClassroom: {classroom.googleapis.com}即命令实际请求的是 Classroom API。认证与权限要求使用本命令前需要先通过gog auth add account --services classroom完成 Classroom API 的 OAuth 授权。命令依赖的 OAuth 范围由 Classroom API 的读取需求决定若账号未启用对应服务会得到明确报错。错误处理与排查wrapClassroomErrorclassroom_helpers.go会对两类典型错误给出可执行的修复提示accessNotConfigured/ Classroom API has not been used说明当前 Google Cloud 项目未启用 Classroom API。报错会提示到 Google Cloud Console 的 API 库页面启用classroom.googleapis.com。insufficientPermissions/ insufficient authentication scopes说明当前账号的 OAuth 授权范围不足。报错会提示重新执行gog auth add account --services classroom补授权限。其余错误如课程不存在、学生不在该课程中原样返回错误信息由 internal/errfmt/googleapi.go 中的映射统一格式化展示。实战场景从列表定位到单学生详情students get通常与列表命令配合使用。gog classroom students list见 gog-classroom-students-list.md可以按页拉取课程内所有学生# 列出课程内学生默认最多 100 条 gog classroom students list 1234567890 # 一次拉取全部学生并以 JSON 输出 gog classroom students list 1234567890 --all --json拿到目标学生的userId或邮箱后再使用students get获取单条详细记录如需教师信息可对照使用gog classroom teachers get。若想一次性概览师生名单也可使用gog classroom roster courseId源码见 classroom_rosters.go。对于自动化脚本推荐组合gog classroom students get 1234567890 aliceexample.com --json --results-only该组合只输出student主对象便于jq等工具直接消费gog classroom students get 1234567890 aliceexample.com --json --results-only \ | jq -r .student.studentWorkFolder.id相关命令与文档gog classroom students — 学生子命令组add/get/list/removegog classroom students add — 添加学生gog classroom students list — 列出学生gog classroom students remove — 移除学生gog classroom — Google Classroom 命令组总览Command index — 全部命令索引本文引用的核心源码与测试位于 internal/cmd/classroom_rosters.go 与 internal/cmd/classroom_helpers.go如需深入理解列表分页、花名册合并等扩展能力可继续阅读同目录下的 classroom_list_helpers.go。【免费下载链接】gogcliGoogle Workspace in your terminal.项目地址: https://gitcode.com/GitHub_Trending/gogcl/gogcli创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表