【发布时间】:2013-01-02 21:43:14
【问题描述】:
StackOverflow 和 Google Apps 脚本的新功能。我感谢任何帮助/指导。
任务:
我正在尝试编写一个 Google Apps 脚本,它将指定文件夹中所有文件的所有权转移给一个所有者。我是 Google Apps 专业版帐户的超级管理员。但是,我既不是原始所有者也不是新所有者,并且出于安全原因,新所有者不能是超级管理员(因此不能运行脚本)。原始所有者和新所有者都在同一个域中。
我找到了 following code,我已经使用它并对其进行了调整,但我收到来自 URLFetchApp 调用的“请求失败,返回代码 400。服务器响应:”错误。
我做了什么:
根据 Google Apps Documents List developers guide我更改了“base”变量来模拟新的文档所有者:
var base = 'https://docs.google.com/feeds/';
到
var base = encodeURIComponent('https://docs.google.com/feeds/'+newOwnerEmail+'/private/full');
我还在 googleOAuth_() 方法中将使用者密钥和秘密更新为正确的值。有了这个,这是导致问题行的整个代码部分:
file.removeEditor(newOwnerEmail);
var base = encodeURIComponent('https://docs.google.com/feeds/'+newOwnerEmail+'/private/full');
var fetchArgs = googleOAuth_('docs', base);
fetchArgs.method = 'POST';
var rawXml = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gAcl='http://schemas.google.com/acl/2007'>"
+"<category scheme='http://schemas.google.com/g/2005#kind' "
+"term='http://schemas.google.com/acl/2007#accessRule'/>"
+"<gAcl:role value='owner'/>"
+"<gAcl:scope type='user' value='"+newOwnerEmail+"'/>"
+"</entry>";
fetchArgs.payload = rawXml;
fetchArgs.contentType = 'application/atom+xml';
var url = base + encodeURIComponent(oldOwnerEmail + '/private/full/'+fileId+'/acl&alt=json');
try { var content = UrlFetchApp.fetch(url, fetchArgs).getContentText(); }
catch (err) { Logger.log(err.message) }
应用程序每次“尝试”执行 UrlFetchApp.fetch() 方法时,应用程序都会“捕获”400 错误。
问题:
我可能在这里遗漏了什么? “fetchArgs”是否以某种方式格式错误(可能是“fetchArgs”正在输入的“rawXML”)?使用新的 Google Drive SDK,使用这个 API 是更好的选择吗?我会很感激我可能错过的任何指导或资源,以及改进如何提出这些问题的任何提示。提前致谢。
【问题讨论】:
标签: google-apps-script google-docs-api