When using this line of code in a Google Apps Script
var user = folders[n].getOwner().getEmail()
I get an error saying I am not authorized to perform such an action (your version may vary, I am translating from italian).
What gives? I am just retrieving an information, such as the owner of a folder.
When the script processes a folder I own, the error does not arise, the error arises when it encounters a folder not of mine. The matter is that this line of code is just for spotting folders which are not of mine, to avoid issuing method that would correctly rise an error, like setTrashed. The script looks for empty folders to delete them, but I cannot delete folders I am not the owner of of course. And yes I am into Google apps for business, does it make some difference?
There isn’t any specifc warning about
file.getOwner().getEmail(), but there is for Class Session.I have no problem with this in a consumer account.
The following function is an excerpt from a gist I posted for a previous question. It wraps the call to
.getEmail()(orgetUserLoginId()if you prefer) in atry ... catchblock, so it avoids errors for users crossing Apps Domains.UPDATE: Since this was first posted, something has changed. Now my consumer account encounters the aforementioned error when trying to access
getOwner()for a file shared from another account. (March 3, 2013)