I am using Java with Android to retrieve a list of Google Classroom courses. Here's the code to make the call. It works fine.
ListCoursesResponse coursesResponse1 = mService.courses().list()
.setPageSize(30)
.setTeacherId("me")
.execute();
However the Classroom API is rather laggy so I'd like to just specify the parameters I need for each course, which are just the coursename and id. I'm hoping this will speed up the response time. There is a setFields parameter that can be used, but when I do this the response fails with "Request contains an invalid argument."
Here's the code I am using
ListCoursesResponse coursesResponse1 = mService.courses().list()
.setPageSize(30)
.setTeacherId("me")
.setFields("name,id")
.execute();
I'm sure the problem is with the setFields string. It is most likely not formatted correctly, but I can't find any documentation on how to format the setFields string.
The answer from @Satheeshkumar is not correct.
The setFields
method is supported and works properly. You can find it on the documentation for the API client.
Also, looking at the API explorer on the documentation page you can see that there is a "Show standard parameters" button.
After clicking this you will see the fields
parameter.
The way this parameter works is by filtering the output and the syntax depends on the structure of the result. By looking at the response body you can see that the response looks like this:
{
"courses": [
{
{
"id": string,
"name": string,
"section": string,
"descriptionHeading": string,
"description": string,
"room": string,
"ownerId": string,
"creationTime": string,
"updateTime": string,
"enrollmentCode": string,
"courseState": enum (CourseState),
"alternateLink": string,
"teacherGroupEmail": string,
"courseGroupEmail": string,
"teacherFolder": {
object (DriveFolder)
},
"courseMaterialSets": [
{
object (CourseMaterialSet)
}
],
"guardiansEnabled": boolean,
"calendarId": string
}
}
],
"nextPageToken": string
}
So, if you only want the name
and the id
fields, your fields
query should be "courses(id,name)"
.