Google App脚本,删除文档共享权限

时间:2012-10-19 09:31:34

标签: google-apps-script google-docs-api

使用URLFetchApp ...

从文档ACL中删除用户的共享权限

以下是我的代码

    function removeSharing(docId,userToRemove)
    {
      var base = 'https://docs.google.com/feeds/default/';
      var fetchArgs = googleOAuthDeleteUser_('docs', base);
      var url = base+'private/full/'+docId+'/acl/'+encodeURIComponent(userToRemove);
      var content = UrlFetchApp.fetch(url, fetchArgs).getContentText(); 
      return 'ok';
    }
    function googleOAuthDeleteUser_(name,scope) {
        var oAuthConfig = UrlFetchApp.addOAuthService(name);
        oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+encodeURIComponent(scope));
        oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
        oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
        oAuthConfig.setConsumerKey("anonymous");
        oAuthConfig.setConsumerSecret("anonymous");

        return {
                oAuthServiceName:name, 
                oAuthUseToken:"always",
                headers : {
                           "GData-Version": "3.0",
                           "If-Match":"*"
                }, 
                method : "DELETE",
                contentType : 'application/x-www-form-urlencoded'
        };
    }

这是给我错误

  

请求返回代码400失败。服务器响应:GData InvalidEntryException   已发布的条目缺少一个或多个必填字段:   范围

请帮忙整理一下。

1 个答案:

答案 0 :(得分:1)

根据the API docs,您的参数应如下所示:

DELETE https://docs.google.com/feeds/default/private/full/resource_id/acl/user:new_writer@example.com

如果userToRemove只有一个电子邮件地址,那么这可能是缺少的范围。