This is my first approach to Google Classroom API. I'm trying to create a script that list the Owner's email of every course.
I thought of doing it by modifying the Quickstart "listCourses()" example, but when trying to get the user profile with Classroom.UserProfiles.get(); I get a 403 PERMISSION_DENIED error.
I've checked that every scope listed has been included:
"oauthScopes": [
"https://www.googleapis.com/auth/classroom.courses",
"https://www.googleapis.com/auth/classroom.profile.emails",
"https://www.googleapis.com/auth/classroom.profile.photos",
"https://www.googleapis.com/auth/classroom.rosters",
"https://www.googleapis.com/auth/classroom.rosters.readonly"
]
And the user running the script is registered as Super Admin on GSuite.
Data access has been checked as allowing data to be shared aswell.
This is the code I'm using
function listCourses() {
var response = Classroom.Courses.list();
var courses = response.courses;
if (courses && courses.length > 0) {
for (i = 0; i < courses.length; i++) {
var course = courses[i];
var owner = Classroom.UserProfiles.get(course.ownerId).emailAddress;
Logger.log('%s (%s) - o: %s - stat: %s', course.name, course.id, owner, course.courseState);
}
} else {
Logger.log('No courses found.');
}
}
As far as I get, that should get me the list of courses, their ID number, the owner's email and the course status.
But execution stops on the UserProfile.get() line and the program stops with a 403 error.
Does anyone know what's the issue and how to solve it? Thank you very much.