How Can I Use The Google Drive Api To Transfer A File To Another User's Drive?
Solution 1:
OK, I figured it out. It looks like I was just using the wrong API. You have to first insert the new permission then you have to delete the old permission. This will send the file to the root of the new user's Drive.
# Insert new permission first
new_permission = {
'value': 'email_of_new_owner@mydomain.com',
'type': 'user',
'role': 'owner'
}
run_new_permission = service.permissions().insert(fileId='FILE_ID_GOES_HERE',body=new_permission).execute()
# Then delete old permission
service.permissions().delete(fileId='FILE_ID_GOES_HERE', permissionId='PERMISSION_ID_GOES_HERE').execute()
Solution 2:
Does it return any kind of error?
I don't think you can "move" the file like that. Try file.insert to his drive then delete from your own.
I have never heard of anyone trying to patch the location of a file to someone else. TBH I can't see how that could work, because you would have to have service authenticated with both your account and his account which is not possible. Even though as you say you are using a service account with access to both account, I seriously drought that the API can support this.
You will need to do this in two steps, insert -> to him Delete -> from you
Update: I just heard from a colleague who is a Google Drive expert, he said he thought it was broken (patching location). He did a quick test and verified this is a broken feature. All it returns is 403 - insufficient permissions
Post a Comment for "How Can I Use The Google Drive Api To Transfer A File To Another User's Drive?"