Python中文
首页
教程
问答
标签
搜索
登录
注册
googledriveapiv3在python中动态更新文件(使用实时数据)
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在尝试用一些新数据更新我创建的文件。本质上,我试图将内容附加到已经创建的文件中。我尝试过不同的方法使用不同的属性,但到目前为止似乎没有任何效果。从v2到v3的迁移似乎使python的开发更加困难。在</p> <p>这是我目前为止的代码</p> <pre><code>def updateFile(fileID, contents): credentials = get_credentials() #this function gets the credentials for oauth http = credentials.authorize(httplib2.Http()) service = discovery.build('drive', 'v3', http=http) # First retrieve the file from the API. #fileCreated = service.files().get(fileId=fileID).execute() #print(dir(fileCreated.update())) # File's new content. file_metadata = { 'name' : 'notes.txt', 'description' : 'this is a test' } fh = BytesIO(contents.encode()) media = MediaIoBaseUpload(fh, mimetype='text/plain') # Send the request to the API. #print(BytesIO(contents.encode()).read()) print(fileID) updated_file = service.files().update( body=file_metadata, #uploadType = 'media', fileId=fileID, #fields = fileID, media_body=media).execute() </code></pre> <p>我尝试过使用MediaFileUpload(它只适用于上传文件),但我附加了一个“字符串”,它是使用语音接口实时生成的,不存储在任何文件中。所以我用了mediaobaseupload。在</p> <p>代码运行时没有任何错误,但文件没有更新。感谢任何帮助。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您还可以使用<code>service.files().get_media(fileId=fileID).execute()</code>获取文件内容并将新内容附加到其中。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
jupyter运行一个旧的pytorch版本
2 回答
Jupyter运行不同版本的卸载库?
3 回答
Jupyter运行指定的键盘快捷键
3 回答
Jupyter通过.local文件“逃逸”virtualenv。我该如何缓解这种情况?
10 回答
Jupyter重新加载自定义样式
5 回答
Jupyter错误:“没有名为Jupyter_core.paths的模块”
5 回答
jupyter错误:无法在随机林中将决策树视为png
9 回答
Jupyter错误'内核似乎已经死亡,它将自动重新启动'为一个给定的代码块
9 回答
Jupyter错误地用阿拉伯语和字母数字元素显示Python列表
9 回答
Jupyter隐藏数据帧索引,但保留原始样式
2 回答
Jupyter集线器:启动器中出现致命错误。。。系统找不到指定的文件
5 回答
Jupyther中相同值的相同哈希,但导出到Bigquery时不相同
7 回答
Jupy上Python的读/写访问问题
6 回答
jupy上没有模块cv
9 回答
Jupy上的排序错误
9 回答
Jupy中bqplot图形的紧凑布局
1 回答
Jupy中matplotlib plot的连续更新
2 回答
Jupy中Numpy函数的文档
10 回答
Jupy中Pandas的自动完成问题
10 回答
jupy中Qt后端的Matplotlib动画
2 回答