简体   繁体   English

使用PyDrive访问共享文件

[英]Access shared file with PyDrive

In my app, using PyDrive and Google Drive, a file is created by user A, saved onto Drive using 在我的应用中,使用PyDrive和Google云端硬盘,用户A创建了一个文件,并使用

self.User.GoogleFile.SetContentString(json.dumps(self.Message))

and the file is shared with user B. When userB reads the file using 并且文件与用户B共享。当userB使用读取文件时

self.Message=json.loads(self.User.GoogleFile.GetContentString())

the message contains the correct data. 该消息包含正确的数据。 If self.Message is modified by user A, and saved using 如果self.Message由用户A修改,并使用保存

self.User.GoogleFile.SetContentString(json.dumps(self.Message))

then, if user B reads the file again, self.Message just contains the original data and not the updated value 然后,如果用户B再次读取该文件,则self.Message仅包含原始数据,而不包含更新的值

Is there any way to refresh the file, or clear the cache, or any command I should run to get user B to get the up to date data? 有什么方法可以刷新文件,清除缓存或我应该执行的任何命令来获取用户B的最新数据?

I now realise that you need to refresh the instance of the Google file list. 我现在意识到,您需要刷新Google文件列表的实例。

I was doing this 我在做这个

drivefiles  = drive.ListFile().GetList()
self.User.GoogleFile = None
while True:    
    for f in drivefiles:
        if f['title'] == 'Hello.txt':
            self.User.GoogleFile = f
            break
        if self.User.GoogleFile!=None:
            self.Message=json.loads(self.User.GoogleFile.GetContentString())
    raw_input("Press Enter to continue...")

when I needed to do this 当我需要这样做时

while True:    
    drivefiles  = drive.ListFile().GetList()
    self.User.GoogleFile = None
    for f in drivefiles:
        if f['title'] == 'Hello.txt':
            self.User.GoogleFile = f
            break
        if self.User.GoogleFile!=None:
            self.Message=json.loads(self.User.GoogleFile.GetContentString())
    raw_input("Press Enter to continue...")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM