简体   繁体   中英

Google Classroom Api batch requests via client library

I Have few questions about google classroom batch requests

  1. I see this notice in documentation page "The Classroom API is currently experiencing issues with batch requests. Use multithreading for heavy request loads, instead.". But the notice below, leads me to a blog post saying if I use a proper client library version and only send homogeneous requests, it is still fine. So is this notice about Classroom API batch requests having issues still valid with a proper client library(google-api-python-client==1.7.11)?

  2. This one is not about batch requests, but leads to the third question below. When we list courses/teachers/students there is a page-size parameter. If it's below 30 it returns correct number but anything above 30 it still returns 30 and I have to send second request to get the rest. Is this behavior documented somewhere?

  3. With batch requests when requests have more results like in Q2, is there a proper way to gather rest of the results. What I have so far is something like this.

def callback_s(id, res, exc):
    if exc:
        print('exception',str(exc))
    t = res.get('students',[])
    np = res.get('nextPageToken')
    if np:
        #how to get rest of the results

 def get_students(courses):
    service = discovery.build('classroom', 'v1', credentials=creds)
    br = service.new_batch_http_request(callback=callback_s)
    for c in courses:
        sr = service.courses().students().list(courseId=c['id'])
        br.add(sr, request_id=c['id'])
    br.execute()

Any pointers would be greatly appreciated.

Classroom API batch request issues:

The warning on top of the page refers to batch requests in general. This certainly includes whatever libraries you use, as long as they are using the same API (and of course, that's the case for the official Python library).

The blog post you mention is about discontinuing support for global batch endpoints, so that batch requests have to be API-specific from now on. That's totally unrelated to the current issues regarding Classroom API batch requests. It's also older than the warning, and is not taking those problems into account.

pageSize maximum value:

The documentation for pageSize doesn't specify the maximum value. For teachers.list and students.list mentions the default value (30). If you're setting a value higher than 30 and still returning only 30, chances are that's the maximum value too.

This doesn't seem to be documented, though:

pageSize : Maximum number of items to return. The default is 30 if unspecified or 0.

Beware, that doesn't seem to be the limit for courses.list (no default pageSize is mentioned, and a call to it retrieves way more than 30).

Multiple pages and batch requests:

You cannot request multiple pages from a list request at once using batch requests, since you need the nextPageToken from the previous page to request the next page (using pageToken ). That is to say, you have to make one request after the other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM