Search code examples
google-classroom

Google Classroom API returns student profile JSON having no email address


Getting student JSON from Google that doesn't contain any email address and user's name contains the value "Unknown User".

 {
     "courseId":"1234",
     "profile":{//No email address
             "id":"openId",
             "name":{"fullName":"Unknown user"},//Why "Unknown user"
             "photoUrl":"correct_url"
     },
     "userId":"openId"
}

We can not access teacher's Google Classroom account so we are trying to reproduce the issue with the test account. It's happening for only few users, working fine for all others.

We are using Google Classroom's Java API.

Example code that we are using:

Classroom service = getGoogleClassRoomService(accessToken);
if(service != null) {
    ListStudentsResponse studentsResponse = service.courses().students().list(courseId).execute();
    List<Student> students = studentsResponse.getStudents();
    if(students != null) {
        for (Student student : students) {
            if (student.getProfile().getEmailAddress() != null) {
                //Processing student data
            }
        }
    }
}

Need to know the scenario when email address can be null for student, technically it should not be null.

Example student profile JSON reference: https://developers.google.com/classroom/reference/rest/v1/userProfiles#resource-userprofile

Scopes requested while authenticating the user:

https://www.googleapis.com/auth/classroom.courses.readonly https://www.googleapis.com/auth/classroom.profile.emails https://www.googleapis.com/auth/classroom.profile.photos https://www.googleapis.com/auth/classroom.rosters.readonly


Solution

  • Could the user have been deleted? In some circumstances the API will return a "user" with "Unknown user" as the name (and no email address) if the user has been deleted.