Google Apps脚本中getOwner方法的奇怪权限问题 [英] Strange permission issue with getOwner method in Google Apps Script

查看:89
本文介绍了Google Apps脚本中getOwner方法的奇怪权限问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google Apps脚本中使用此行代码时,请在

  var user = folders [n] .getOwner()中使用此行代码。 getEmail()

我收到一个错误,说我没有被授权执行这样的操作(您的版本可能不同的,我翻译从意大利语)。



什么给?我只是检索信息,如文件夹的所有者。






当脚本处理我拥有的文件夹时,错误不会出现,遇到不属于我的文件夹时会出现错误。问题是,这一行代码仅仅用于查找不属于我的文件夹,以避免发布会正确引发错误的方法,如 setTrashed 。脚本查找空文件夹以删除它们,但我无法删除文件夹,我当然不是它的主人。是的,我进入谷歌应用程序业务,它有什么区别?

解决方案

没有任何关于 file.getOwner()。getEmail(),但是课程会话
$ b


在有限特权执行中(例如响应onOpen或
onEdit),我们只返回活动的标识用户,如果
用户和脚本所有者都是同一个域的一部分。这是
保护消费者用户的隐私,他们可能不希望他们的电子邮件
地址暴露。


我在这个消费账户中没有问题。



以下函数摘自我为之前的问题发布的要点。它将 .getEmail()(或 getUserLoginId())调用封装在 try ... catch block,所以它避免了通过Apps Domains的用户出错。

 函数getFileInfo(file,fileType){
var fileInfo = {
id:file.getId(),
name:file.getName(),
size:file.getSize ),
类型:(文件类型==文件)? docTypeToText_(file.getFileType()):folder,
created:file.getDateCreated(),
description:file.getDescription(),$ b $ owner:file.getOwner()

try {
fileInfo.owner = file.getOwner()。getEmail()//。getUserLoginId()
} catch(e)
{
//可能的许可问题
fileInfo.owner =未知;
}
返回fileInfo;

更新:已经改变。现在,我的客户帐户在尝试访问从另一个帐户共享的文件的 getOwner()时遇到上述错误。 (2013年3月3日)

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.

In limited-privilege executions (such as in response to onOpen or onEdit), we only return the identity of the active user if both the user and the script owner are part of the same domain. This is to protect the privacy of consumer users, who may not want their email address exposed.

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() (or getUserLoginId() if you prefer) in a try ... catch block, so it avoids errors for users crossing Apps Domains.

function getFileInfo (file,fileType) {
  var fileInfo = {
    id: file.getId(),
    name: file.getName(), 
    size: file.getSize(),
    type: (fileType == "file") ? docTypeToText_(file.getFileType()) : "folder",
    created: file.getDateCreated(),
    description: file.getDescription(),
    owner: file.getOwner()
  }
  try {
    fileInfo.owner = file.getOwner().getEmail()//.getUserLoginId()
  } catch(e)
  {
    // Possible permission problem
    fileInfo.owner = "unknown";
  }
  return fileInfo;
}

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)

这篇关于Google Apps脚本中getOwner方法的奇怪权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆