muteHttpExceptions = true会导致身份验证失败

Jas*_*tra 6 google-api google-apps-script oauth-2.0

使用Google Apps电子邮件设置API,将使用以下脚本删除委托.如果发生错误,例如尝试删除不存在的委托,则返回以下消息:

例外:返回代码400的请求失败.截断的服务器响应:<xml version ="1.0"encoding ="UTF-8"?> <AppsForYourDomainErrors> <error errorCode ="1303"invalidInput ="XXXX@XXXX.com"reason = "E ...(使用muteHttpExceptions选项检查完整响应)

但是,使用muteHttpExceptions = true身份验证失败时:

例外:无法对服务进行身份验证:google

这迫使我使用try/catch结构而不是检查HTTPResponse对象.我想知道为什么会这样,以及如何解决它.

测试功能:

   function test() {
      var consumerKey = 'XXXX';
      var consumerSecret = 'XXXX';
      var domain = 'XXXX.com';
      var userName = 'XXXX'
      var delegateName = 'XXXX@XXXX.com'
      var serviceName = 'google';
      var scope = 'https://apps-apis.google.com/a/feeds/emailsettings/2.0/';


      var oAuthConfig = UrlFetchApp.addOAuthService(serviceName);
      oAuthConfig.setRequestTokenUrl('https://www.google.com/accounts/OAuthGetRequestToken?scope=' + scope);
      oAuthConfig.setAuthorizationUrl('https://www.google.com/accounts/OAuthAuthorizeToken');
      oAuthConfig.setAccessTokenUrl('https://www.google.com/accounts/OAuthGetAccessToken');
      oAuthConfig.setConsumerKey(consumerKey);
      oAuthConfig.setConsumerSecret(consumerSecret);

      var fetchParameters = {};
      fetchParameters.oAuthServiceName = serviceName;
      fetchParameters.oAuthUseToken = 'always';
      fetchParameters.method = 'DELETE';
      fetchParameters.muteHttpExceptions = false;

      try {
        var url = 'https://apps-apis.google.com/a/feeds/emailsettings/2.0/'+ domain + '/' + userName + '/delegation/' + delegateName;
        var result = UrlFetchApp.fetch(url, fetchParameters);
      } catch (e) {
        Logger.log(e);
      }
    }
Run Code Online (Sandbox Code Playgroud)

mha*_*sey 1

此问题已作为票证 3478发布到 Google Apps 脚本问题跟踪器,并被确认为错误。该票证仍然开放,但已提出以下解决方法

  1. 在您的 Google 帐户的安全设置中撤销对 www.google.com 和 Apps 脚本源(电子表格等)的访问权限。

  2. 将 oAuthServiceName 参数更改为其他值。

  3. 重新运行脚本