Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to Programmatically Copy a Google Spreadsheet and Transfer Ownership from a GCP Cloud Function

aejaz
New Member

I'm trying to programmatically perform the following actions from within a Google Cloud Function:

  1. Copy a Google Spreadsheet that exists in my personal Google account.
  2. Transfer ownership of the copied spreadsheet to another Google account (different email).

Here’s what I’ve tried so far:

  • Using a Service Account (with all necessary Drive scopes).
  • Using OAuth 2.0 refresh token of my personal Google account.

In both cases, the ownership transfer request fails with this error:

 

 

I/O error: 403 Forbidden
POST https://www.googleapis.com/drive/v3/files/156cD3L0-Yg_33qENsZseA6FiBHkwL9PpqYuzp7Q7whQ/permissions?sendNotificationEmail=true&transferOwnership=true
{
"code" : 403,
"errors" : [
{
"domain" : "global",
"message" : "Consent is required to transfer ownership of a file to another user.",
"reason" : "consentRequiredForOwnershipTransfer"
}
],
"message" : "Consent is required to transfer ownership of a file to another user."
}

 

 


Has anyone successfully transferred file ownership via the Google Drive API from within a Google Cloud Function, especially when dealing with personal Google accounts?

I would appreciate any help on:

  • How to handle the consentRequiredForOwnershipTransfer error.
  • Whether this kind of transfer is even allowed programmatically without manual intervention.
  • Any best practices or workarounds for this scenario?

Thanks in advance!

0 0 27
0 REPLIES 0