Reputation: 602
I'm trying to do what I thought would be a simple operation but I'm having some issues with the Google APIs. I've got two Google Credentials, one from a service account and one Access/Refresh from a user who has authenticated to the application.
The Service Account has the Domain Wide Delegation.
On a Team Drive that the Service Account can access (Templates) I have a doc that I would like to copy to the User's My Drive (root). I have the ID of the folder through:
String userRootId = userCredential.drive().files().get( "root" ).setFields( "id" ).execute().getId();
Which returns the proper identifier. When I use the Service Account to Copy the file, I can make copies in the Team Drive all day. It's when I go to copy it to the user's drive that I get "File not found: $userRootId".
I'm assuming that this stems from the Service Account not being able to access the User's My Drive. How can I make this operation work? Has anyone attempted this?
Upvotes: 1
Views: 621
Reputation: 602
Okay so I figured out a way that works for my implementation. I have the Access/Refresh token of the target user drive. If you don't have that, I'm not sure how you could make it work. The steps are as follows:
Get the SERVICE ACCOUNT root, using:
String serviceRootId = this.serviceManager.drive().files().get( "root" ).setFields( "id" ).execute().getId();
Use the service account to copy the file
This all seems a bit silly, but I think it's the only way to do it given the current limitations in Google Drive. I would've expected the service account with the Domain Wide Delegation to be allowed to just copy the thing, but it appears not.
If there's a better way to this, I'm very excited to learn, but for now this seems to work.
Upvotes: 1