revision method list() return only 3 revisions

30 views Asked by At

the code below I use to connect to Google Cloud and get specific sheet revisions (old versions of the sheet) it was working fine until yesterday, although I am using maxResults=100 but it only gives me 3 results

creds = gsheet_api_check(SCOPES)
service = build("drive", "v2", credentials=creds)

  history_list = (
        service.revisions().list(fileId=file_id, maxResults=100).execute()
    )

I even tried the method on the Cloud website using my Cloud mail, where pageSize works as same as the maxresults attribute in the API(controlling the number of revisions) but gives the same 3 results only

enter image description here

can anyone help me out or have information about Cloud updates that could result in that?

trying to get old versions of the sheet using Google API to be used as a pandas data frame, I need a way to retrieve older versions that at least a day ago knowing that the sheet is accessed by a lot of employees and edited 10s times a day so to retrieve yesterday versions I will need to get around 100 revisions back.

1

There are 1 answers

1
Dion V On

It might be that the API might limit the number of revisions returned in a single request, even if maxResults is set to 100. Implementing pagination using pageToken to iterate through multiple pagae of results. Here is a sample code for reference:

page_token = None
revisions = []
while True:
    history_list = (
        service.revisions().list(fileId=file_id, maxResults=50, pageToken=page_token).execute()
    )
    revisions.extend(history_list.get('items', []))
    page_token = history_list.get('nextPageToken')
    if not page_token:
        break

You may want to double-check your API quotas as Google Drive API has quotas on the number of requests you can make per day. Try monitoring the quota usage and adjust the code or API calls if necessary.