0

in Google drive, I am trying to copy a folder from a personal account (Account A) to a corporate workspace account(Account B).

I am trying to run the script, credit to ref

/**
 * Entry point to execute with the Google Apps Script UI
 */
function copyFolder() {
  // Get the folders (by ID in this case)
  sourceID = "xxxxxxxxxx"
  targetID="xxxxxxxxx
  const toCopy = DriveApp.getFolderById(sourceID )      
  const copyInto = DriveApp.getFolderById(targetID) //error in  this line 

  // Call the function that copies the folder
  copyFolder_(toCopy, copyInto)
}

I am trying to run this script as the user in account A. Error as follows.

Exception: No item with the given ID could be found. Possibly because you have not edited this item or you do not have permission to access it.

The reason is targetID ref to a folder in Account B.

How to grant the ACCOUNT A user the right to put something in ACCOUNT B?

Luk Aron
  • 1,235
  • 11
  • 34
  • 1
    When you authorize your app its for a single user. If you need access to another account you will need to authorize the second account. As far as i know app script is singular you cant log into multiple accounts. I wonder how ever if your gsuite admin could give your personal account access to the domain. – Linda Lawton - DaImTo Jul 26 '21 at 17:25
  • You will have to share the spreadsheet with the id or if you are also copying the spreadsheet also then you will have to provide the new id. – Cooper Jul 26 '21 at 18:16

1 Answers1

0

Your are using Google Apps Script UI, so I think the folder targetID would not change (frequently), right?

In such case, you only need to get the permission of folder targetID from Account B in advance.

idfurw
  • 5,727
  • 2
  • 5
  • 18