3

How can I determine if a user that is logged into my app is a Teacher or a Student?

I can successfully log in to my app using a Google Classroom test account, but when I look at the information retrieved, I see nothing in regards to role. I've looked through the API but so far I've only seen calls related to getting courses and rosters. I tried the user profile call, but the info returned did not include a role.

At a basic level, I just want to do loggedInUser.role === teacher.

Edit: Updated for clarification. I am not looking for courses.students or courses.teachers. I consider those roster information. I already have a profile from a logged in user. I shouldn't have to see what role they are by listing teachers in a course.

Merlin -they-them-
  • 2,731
  • 3
  • 22
  • 39

2 Answers2

2

You're looking for courses.students and courses.teachers:

https://developers.google.com/classroom/reference/rest/v1/courses.students https://developers.google.com/classroom/reference/rest/v1/courses.teachers

Once you have a course ID you can query these using the "list" request:

https://developers.google.com/classroom/reference/rest/v1/courses.teachers/list https://developers.google.com/classroom/reference/rest/v1/courses.students/list

Stephen Woods
  • 4,049
  • 1
  • 16
  • 27
  • Updated my question to clarify why this doesn't answer my question. Thank you for the effort though – Merlin -they-them- Feb 02 '16 at 03:45
  • 1
    You'll still need to go through with it. Aside from the 2 methods specified by @stephen-woods, there are `invitations` and `userProfiles` methods which don't have `roles` like you're asking. – adjuremods Feb 02 '16 at 07:28
2

Via the Classroom API, you can only determine if a user is a teacher or a student relative to a particular course. (It's possible for a user to be a teacher in one course, and a student in another.)

If you need to determine if a user is a real-world teacher or student, you need to do this via a mechanism separate from Classroom.

You might also like to star this issue to learn about any possible improvements to the API.

mjs
  • 63,493
  • 27
  • 91
  • 122