本文介绍了muteHttpExceptions = true引发认证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用,代理人将被删除下面的脚本。如果发生错误,例如试图删除不存在的委托,则返回以下消息:

然而,当使用 muteHttpExceptions = true 验证失败:
$ b

这迫使我使用try / catch结构而不是检查 HTTPResponse

测试函数:

 函数test(){
var consumerKey ='XXXX';
var consumerSecret ='XXXX';
var domain ='XXXX.com';
var userName ='XXXX'
var delegateName ='[email protected]'
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;

尝试{
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);


$ / code>


解决方案

问题已作为和。该机票保持打开状态,但:


Using the Google Apps Email Settings API a delegate is deleted with the script below. If an error occurs, for example trying to delete delegates that do not exist, the following message is returned:

However when using muteHttpExceptions = true the authentication fails:

This forces me to use a try / catch structure instead of examining the HTTPResponse object. I would like to know why this is happening and how to solve it.

The test function:

   function test() {
      var consumerKey = 'XXXX';
      var consumerSecret = 'XXXX';
      var domain = 'XXXX.com';
      var userName = 'XXXX'
      var delegateName = '[email protected]'
      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);
      }
    }
解决方案

This question has been posted to the Google Apps Script issue tracker as ticket 3478 and acknowledged as a bug. The ticket remains open but the following workaround has been proposed:

这篇关于muteHttpExceptions = true引发认证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 02:02