gpt4 book ai didi

google-apps-script - muteHttpExceptions = true 抛出身份验证失败

转载 作者:行者123 更新时间:2023-12-02 06:20:14 24 4
gpt4 key购买 nike

使用Google Apps Email Settings API使用以下脚本删除委托(delegate)。如果发生错误,例如尝试删除不存在的委托(delegate),则会返回以下消息:

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)

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

Exception: Failed to authenticate for service: 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);
}
}

最佳答案

此问题已发布到 Google Apps 脚本问题跟踪器,编号为 ticket 3478acknowledged as a bug 。票证仍然开放,但 the following workaround has been proposed :

  1. Revoking access in your Google Account's Security settings to both www.google.com AND the source of Apps Script (spreadsheet etc).

  2. Change the oAuthServiceName parameter to something else.

  3. Re-running the script

关于google-apps-script - muteHttpExceptions = true 抛出身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20238787/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com