Can anyone help me list the students for a specific class using Google Classroom API. I have searched through the API documentation and I can't seem to find out how to do it.
I basically need to do this https://developers.google.com/classroom/reference/rest/v1/courses.students/list
Here is the code I am using. It works with other functions (e.g. $service->students->listCoursesStudents($course_id);
):
function G_Course_Roster($course_id) {
$clientId = '111111111111111111';
$serviceAccountName = 'name@vocal-affinity-11111111.iam.gserviceaccount.com';
$delegatedAdmin = 'email@email.net';
// service account p12 key file:
$keyFile = '/home/rootfolder/vendor/Google OAuth Login-1111111111.p12';
$appName = 'name';
$scopes = array(
'https://www.googleapis.com/auth/classroom.profile.emails',
'https://www.googleapis.com/auth/classroom.profile.photos',
'https://www.googleapis.com/auth/classroom.rosters.readonly'
);
$creds = new Google_Auth_AssertionCredentials(
$serviceAccountName,
$scopes,
file_get_contents($keyFile)
);
$creds->sub = $delegatedAdmin;
$client = new Google_Client();
$client->setApplicationName($appName);
$client->setClientId($clientId);
$client->setAssertionCredentials($creds);
$service = new Google_Service_Classroom($client);
$optParams = array(
'courseId' => $course_id
);
$response = $service->students->listCoursesStudents($course_id);
return $response;
}