在Google Drive SDK中使用实时更新方法的示例?

时间:2013-12-28 06:23:18

标签: python google-drive-api google-drive-realtime-api

有没有人举例说明https://developers.google.com/drive/v2/reference/realtime/update

以下代码中revision_bodybase_body的内容如下:

1)字符串模型

2)列表模型

3)地图模型

file = service.realtime().update(
    fileId=fileId, 
    media_body=revision_body, 
    baseRevision=base_body)
.execute()

1 个答案:

答案 0 :(得分:1)

service.realtime().update(
   fileId=fileId, 
   media_body=rev, 
   baseRevision=base
).execute()

其中revbase如下所示:

<强>碱

base_body = service.realtime().get(fileId=fileId).execute()
base = MediaIoBaseUpload(
   StringIO.StringIO(base_body), 
   'application/vnd.google-apps.drive-sdk'
)

<强>启:

rev_body = '{"appId":"...","revision":2,"data":{"id":"root","type":"Map","value":{"text":{"id":"%s","type":"EditableString","value":"Hello Realtime World!"}}}}' % randomString(12)

rev = MediaIoBaseUpload(StringIO.StringIO(rev_body), 'application/vnd.google-apps.drive-sdk')

其中randomString(n)

def randomString(length):
  return ''.join(random.choice(string.letters + string.digits + '_-') for i in range(length))

```