jsongoogle-oauthgoogle-api-python-clientgoogle-docs-apipython-3.12

How to fix error in get doc from Google API?


from google.oauth2.service_account import Credentials
from googleapiclient.discovery import build
import random
import msvcrt 
import json

credentials_doc = 'service_account.json'


service_account_info = json.load(open(credentials_doc))
credentials = Credentials.from_service_account_info(service_account_info)
service = build('drive', 'v3', credentials=credentials)

document_id='my_doc_drive_id'

document = service.comments().get(documentId=document_id).execute()
print(document)

error: document = service.comments().get(documentId=document_id).execute() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ raise TypeError("Got an unexpected keyword argument {}".format(name)) TypeError: Got an unexpected keyword argument documentId

how can i get my document ** drivelink:https://docs.google.com/document/d/my_doc_drive_id**

I want to get my drive doc infos and processing incomings


Solution

  • From how can i get my document ** drivelink:https://docs.google.com/document/d/my_doc_drive_id** and I want to get my drive doc infos and processing incomings, I believe that your goal is as follows.

    Modification points:

    If you want to retrieve the Google Document, it is required to use Google Docs API.

    Modified script:

    from google.oauth2.service_account import Credentials
    from googleapiclient.discovery import build
    import json
    
    credentials_doc = 'service_account.json'
    
    service_account_info = json.load(open(credentials_doc))
    credentials = Credentials.from_service_account_info(service_account_info)
    
    service = build('docs', 'v1', credentials=credentials)
    
    document_id='my_doc_drive_id' # Please set your Google Document ID.
    
    document = service.documents().get(documentId=document_id).execute()
    print(document)
    

    Note:

    References: