How can I distinguish between students and teacher

2019-09-12 07:49发布

问题:

Using the Google Classroom API method userProfile, I can get various information about a user, including their name and email address, but not whether they are a student or teacher. How can I determine whether a user is a student or teacher?

回答1:

Classroom does have the concept of teachers and students, however the distinction between teachers and students is only meaningful relative to a particular course (it’s possible for a user to be a “teacher” of one course and a “student” of another) and so you might not be able to use these categories to apply access controls in the way you were expecting.

For example, if alice@school.edu is a member of a particular course’s courses.teachers collection, and bob@school.edu is a member of courses.students, then you can use this information to decide that bob@school.edu should not see certain content created by alice@school.edu. (For example, you might not want to show Bob the answers to a quiz that Alice has created on your website, just the questions.)

However, because by default all users can create courses, you probably do not want to show alice@school.edu sensitive information created by teachers of other courses, information intended for teachers that you provide (for example, if you are a textbook publisher), or giving her domain-wide admin features.

If you need to distinguish between “real-world” teachers and students, we recommend that you do this via a mechanism entirely separate from Classroom, such as checking that the user’s email address appears in:

  • a separately-maintained list of teachers (e.g. CSV uploaded by admin)
  • the classroom_teachers group – domain administrators can choose to verify teachers to allow them to create new classes (use the Directory API to list a user’s groups)


回答2:

Classroom api dosent provide global role for a teacher or a student its vary from course to course so you can just call student/teacher api after that you will get json output and you find a special permission for teacher "Create Course" it will help you to recognized that the person is teacher.

"permissions": [
   {
       "permission": "CREATE_COURSE"
   }
]

in case of student this array will be null.