I've been trying to get the email of the user that submitted a response to a short answer assignment. In all of my other experiences using the Google Classroom API, the "userId" parameter has been the student's email address, but when I call getUserId on the StudentSubmission object, I get a weird string of numbers. How do I get the email associated with the submitted response?
Here's my code for reference:
ListStudentSubmissionsResponse submissionResponse = service.courses().courseWork().studentSubmissions().list(courseId, assignmentId).execute();
List<StudentSubmission> submissions = submissionResponse.getStudentSubmissions();
for (StudentSubmission sub : submissions)
{
System.out.println(sub.getId() + "\t" + sub.getUserId() + "\t" + sub.getState());
}
And this is the response that I am getting:
Cg4I2vWq_8IDEIWck4DDAw 108878473486432178050 CREATED
Does anyone know what is going on here?
Don't not read the docs: retrieve_student_responses
Students are identified by the unique ID or email address of the user, as returned by the Google Admin SDK.
So there's clearly no guarantee it will return the email..
If you read the docs you can find how to properly retrieve the email for a student id: retrieve_a_users_profile
To retrieve the abridged profile, including ID and name, for a user, call
userProfiles.get()
with the user's ID, email, or "me" for the requesting user.To retrieve the
emailAddress
field, you must include theclassroom.profile.emails
scope.