2014-08-31 578 views
1

我有一个网络应用程序,允许用户创建和编辑Google云端硬盘文件。我能够创建并保存新文件。但是当我想更新现有文件时,我无法做到这一点。根据Google Drive API的参考,更新现有的文件用户需要为该文件提供'fileId'。但是,如何获得特定文件的fileId?我有我的文件标题,但如何获得'fileId'?如何获取Google Drive文件的'fileId'?

我使用下面的代码来做到这一点:

fileId = <How to get this?> 
media_body = MediaFileUpload(filename, mimetype='text/x-script.phyton', resumable=True) 
body = { 
    'title': filename, 
    'description': 'File saved from Pythonista app', 
    'mimeType': 'text/x-script.phyton' 
} 
existing_file = service.files().get().execute() 
if existing_file: 
    resource = service.files().update(
     fileId=fileId, 
     body=existing_file, 
     newRevision=True, 
     media_body=media_body).execute() 

回答

1

你总是需要保持该ID,当你得到的文件。与Dropbox不同的是,GD的路径和文件名几乎不会提供任何内容。

请参阅本资源:

当你得到的,你正在做的查询与此类似Link: Google Drive SDK API for files listing

里面的“文件”的用户项目列表容器希望找到这样的数据:

{ 
    "kind": "drive#file", 
    "id": string, <<<<< HERE 
    "etag": etag, 
    **** 
    "title": string, <<<<<<< Name of the file you already use 
    **** 
    } 
} 

Link: Google Drive SDK API for file resource info

因此,在你的代码,你应该通过ID的大部分时间,文件名不是关键在这里。

相关问题