Damon
Damon

Reputation: 841

Examples of using the Realtime update method in the Google Drive SDK?

Does anyone have any example illustrating https://developers.google.com/drive/v2/reference/realtime/update?

What would revision_body and base_body look like in the code below for a:

1) String Model

2) List Model

3) Map Model

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

Upvotes: 1

Views: 264

Answers (1)

Damon
Damon

Reputation: 841

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

where rev and base derived as shown below:

base:

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

rev:

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')

where randomString(n):

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

```

Upvotes: 1

Related Questions