您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何通过python API将json / pickle文件转储并读入Google Drive?

5b51 2022/1/14 8:20:33 python 字数 3708 阅读 454 来源 www.jb51.cc/python

我从这里下载了开始代码:http://goo.gl/Tcxkod并按照说明安装了XP001中的sample.py:alvas@ubi:~/git/UniversalCorpus/drive-cmd-line-sample$python sample.py Success! Now add code here. 但是如何将pickle / json文件转储到驱

概述

我从这里下载了开始代码http://goo.gl/Tcxkod并按照说明安装了XP001中的sample.py:

alvas@ubi:~/git/UniversalCorpus/drive-cmd-line-sample$python sample.py
Success! Now add code here.

但是如何将pickle / json文件转储到驱动器上然后检索它以从python中读取?

我点击了dev文档,除了repr和源代码本身之外没有任何线索:https://developers.google.com/resources/api-libraries/documentation/drive/v2/python/latest/drive_v2.files.html#get

我测试了PyDrive,我觉得它非常直截了当.这是我做的:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth()

drive = GoogleDrive(gauth)

# Upload a json file (will be identical for a pickle file)
json_file = drive.CreateFile()
json_file.SetContentFile('wopwop.json')
json_file.Upload() # Files.insert()
print json_file['title'],json_file['id']

# Download the same json file
same_json_file = drive.CreateFile({'id': json_file['id']})
same_json_file.GetContentFile('test.json')  # Save Drive file as a local file

这段代码有两个“问题”:

>如果您在每次使用时都同意,它会在浏览器中询问您.阅读this page让他记住你的答案.
>如您所见,您需要记住文件的唯一标识符(id).您可以将它们放在数据库或本地json文件中.您也可以使用PyDrive到list all files matching a query,从而为您提供ID.

没有PyDrive

如果您对使用PyDrive不感兴趣,我强烈建议您阅读其代码.如果我必须这样做,我会在pydrive.files中放置3个断点(或打印):

>在_FilesInsert上的self.auth.service.files()行.insert(** param).execute()
>在_FilesUpdate上行self.auth.service.files().update(** param).execute()
>在_DownloadFromUrl上的self.auth.service._http.request(url)行和构造函数中查看他如何获取url(它在self.Metadata中)

您已经使用在sample.py中下载的代码获得服务,因此您只需要知道param字典中的内容即可了解正在进行的操作.

但是,你应该使用PyDrive;)

总结

以上是编程之家为你收集整理的如何通过python API将json / pickle文件转储并读入Google Drive?全部内容,希望文章能够帮你解决如何通过python API将json / pickle文件转储并读入Google Drive?所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶