muteHttpExceptions = true引发认证失败 [英] muteHttpExceptions = true throws authentication failure
问题描述
使用 Google Apps电子邮件设置API ,代理人将被删除下面的脚本。如果发生错误,例如试图删除不存在的委托,则返回以下消息:
例外:请求返回失败代码400.截断的服务器
响应:
invalidInput =XXXX @ XXXX.comreason =E ...(使用muteHttpExceptions
选项来检查完整响应)
然而,当使用 muteHttpExceptions = true
验证失败:
$ b
例外:无法验证服务: google
这迫使我使用try / catch结构而不是检查 HTTPResponse $ c $我想知道为什么会发生这种情况,以及如何解决它。
测试函数:
函数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;
尝试{
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>
问题已作为 ticket 3478 和确认作为一个错误。该机票保持打开状态,但以下解决方法具有建议:
撤销您的Google帐户安全设置中的访问权限.google.com和Apps脚本(电子表格等)的来源。
- / b>
将oAuthServiceName参数更改为其他名称。 重新运行脚本
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:
Exception: Request failed for returned code 400. Truncated server response: <xml version="1.0" encoding="UTF-8"?> <AppsForYourDomainErrors> <error errorCode="1303" invalidInput="XXXX@XXXX.com" reason="E... (use muteHttpExceptions option to examine full response)
However when using muteHttpExceptions = true
the authentication fails:
Exception: Failed to authenticate for service: google
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 = '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);
}
}
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:
Revoking access in your Google Account's Security settings to both www.google.com AND the source of Apps Script (spreadsheet etc).
Change the oAuthServiceName parameter to something else.
Re-running the script
这篇关于muteHttpExceptions = true引发认证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!