Reputation: 79
Background:
Language: Python Libs version: oauth2client (1.4.6) apiclient (1.0.2)
Script tasks:
1 - Search for files shared with account "A" by account "B"
param['pageToken'] = page_token
param['maxResults'] = 1000
param['q'] = "not '%s' in owners and trashed = false" % (account_A_email)
files = service.files().list(**param).execute()
2 - Impersonate as account "B" using "SignedJwtAssertionCredentials" and set account "A" as owner
new_permission = {}
new_permission['value'] = account_A_email
new_permission['type'] = 'user'
new_permission['role'] = 'owner'
service.permissions().insert(fileId=file_id, body=new_permission).execute()
# Note: I have tried service.permissions().update() but it did not work
Issue:
Once the new permission applied on any file, the file appears on account "A" root folder as well as the original location. This behavior is similar to "Add to my Drive" in the Drive UI.
Any idea how to stop the "Add to my Drive" behavior?
Thanks in advance,
Upvotes: 3
Views: 9328
Reputation: 79
Ok I did the following and it worked after couple of hours and loads of cups of coffee :)
Instead of using "which causes the issue":
service.permissions().insert(fileId=file_id, body=new_permission).execute()
Use the following:
param_perm['value'] = new_owner
param_perm['type'] = 'user'
param_perm['role'] = 'owner'
service.permissions().update(fileId=file_id,
permissionId=perm_id,
body=param_perm,
transferOwnership=True).execute()
What changed from my previous trial is the permissionId which is the "new owner" permission id not the previous owner.
Upvotes: 4