0

I have a document on Google Docs, for example: https://docs.google.com/document/d/1U_Be02ViQp0UKPYNQo184ks4Vv-ey8mNoawJtTyC1R8

I want to rename a specific version of the document to some name like "Version 1.0 - 20240101". I want to do it programmatically using Python/JS/... or REST API.

Rename only latest version is also ok.

Please help!

This is code to get all revisions of a document but I want to edit and rename a revision. Just keep it here to let you start faster.

import os
from google.oauth2 import service_account
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
import urllib.request


def get_revision_history(fileId):
    # don't commit your token file to the repo
    KEY_FILE = 'token.json'
    DOWNLOAD_DIR = 'download'
    curDir = os.path.join(DOWNLOAD_DIR, fileId)
    if not os.path.isdir(curDir):
        os.mkdir(curDir)

    # authenticate with the Google APIs using your service account
    credentials = service_account.Credentials.from_service_account_file(
        KEY_FILE,
        scopes=['https://www.googleapis.com/auth/documents',
                'https://www.googleapis.com/auth/drive']
    )

    # initialize the Google Drive API client, only v2 works (not v3)
    drive_service = build('drive', 'v2', credentials=credentials)

    try:
        # get the revision history of the Google Docs
        revisions = drive_service.revisions().list(fileId=fileId).execute()
        print(f"{fileId}: {len(revisions['items'])} revisions found")


    except HttpError as error:
        print(f"An error occurred: {error}")
        raise error
        return None


if __name__ == '__main__':
    # fileId = # it's in the Google Docs link, https://docs.google.com/document/d/fileId/
    fileId = "1U_Be02ViQp0UKPYNQo184ks4Vv-ey8mNoawJtTyC1R8"
    get_revision_history(fileId)

I couldn't find API to rename a version.

3
  • From what I know, the feature to rename a specific version of the document to some name is currently not possible with the Google Drive API. Both Service: googleapis.com/drive/v2 and Service: googleapis.com/drive/v3 are able to access version histories. However, they lack the functionality to allow individuals to rename them. Commented Apr 15, 2024 at 14:36
  • I recommend that you submit a feature request, as that's the best way to tell Google about these kinds of things. Commented Apr 15, 2024 at 14:36
  • Thank you for your answers. I submitted a feature request to GG. Commented Apr 16, 2024 at 0:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.