1

使用 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 失败。服务器响应:GDataInvalidEntryException发布的条目缺少一个或多个必填字段:范围

请帮忙解决这个问题。

4

1 回答 1

1

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

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

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

于 2013-06-26T17:29:51.473 回答