Search code examples
pythongspreadpydrive

pydrive: how do I rename the title of a google spreadsheet once I know the id?


Here under "Update file metadata" it shows how to change the title from a created file. I'm looking for how to change the title if I know the id or key. Or is there a way to do it in gspread?


Solution

  • i found it

    from pydrive.auth import GoogleAuth
    from pydrive.drive import GoogleDrive
    gauth = GoogleAuth()
    gauth.LocalWebserverAuth()
    drive = GoogleDrive(gauth)
    
    id='xxxxxxxxxxxxxxxxxxxxxxxx'
    a=drive.auth.service.files().get(fileId=id).execute()
    a['title']="new title"
    update=drive.auth.service.files().update(fileId=id,body=a).execute()