Search code examples
pythongoogle-api-python-client

how to get the next page in the google books api for python?


I'm trying to work out how to use the google books api for python - finding it difficult to find any docs on - so am really just looking at the code at the moment and trying to go from there.. I finally worked out that you can provide your api key as "DeveloperKey" when creating a service, which I haven't seen written anywhere - and I figured out how to do a search, so this works:

from googleapiclient.discovery import build
service = build( "books", "v1", developerKey="...my api key...")
volumes = service.volumes()
request = volumes.list( q = "David eddings")
result = request.execute()
print( result )

However - the result comes back with totalItems of 1162 - but an items collection of 10 items - and I can't figure out at all how to ask for the next set of items, or even to change the number of items that comes back in the first place.

Is there a way? And is this documented anywwhere? I can find documentation on the google rest api for books, but I can't find a word anywhere on the python api for books.


Solution

  • I think most of the parameters are listed here.

    You can use startIndex parameter to paginate your results and maxResults parameter to get more than 10 results(which is the default) in a single request.

    For example: https://www.googleapis.com/books/v1/volumes?q=search+terms&maxResults=20&startIndex=20

    This will make a request for 20 elements, starting from 20, skipping all elements from 0 to 19.