0

我正在使用电子邮件奥迪 API 以加密形式下载用户的邮箱。当我将代码写入谷歌脚本并尝试运行时,它会给出错误 504:超时错误。当我使用 OAuth 游乐场执行此操作时,我成功下载了邮箱。 .所以请给我一些建议来解决这个问题。

Code :
function downloadMailBox(user){
var user='user@mydomain.com'
var base='https://apps-apis.google.com/a/feeds/compliance/audit/'
var fetchArgs=googleOAuth_('google',base)
var userID=user.split('@')[0]
//Logger.log(userID)
var rawXml='<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:apps="http://schemas.google.com/apps/2006">'+
    '<apps:property name="packageContent" value="FULL_MESSAGE"/></atom:entry>'
    fetchArgs.payload=rawXml
var uriForMailbox=base+'mail/export/mydomain.com/'+userID
UrlFetchApp.fetch(uriForMailbox,fetchArgs)
}


function googleOAuth_(name,scope) {
  var oAuthConfig = UrlFetchApp.addOAuthService(name);
  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("mydomain.com");
  oAuthConfig.setConsumerSecret(consumersecret);
  return {oAuthServiceName:name, 
  oAuthUseToken:"always",
  contentType:'application/atom+xml',
  method:'POST'
  }; 

}
4

2 回答 2

0

After how much time, you are getting the error? Google has script execution time limit which is around 5 minutes. Any script, which will take time longer than this will time out. There are other limits as well. You can check the details on Apps Script Dashboard.

You need to optimize the script or break your operation in small batches. Here are some tips to optimize google script. Link#1 Linkk#2

于 2012-10-31T11:54:10.923 回答
0

我找到了一个解决方案...我刚刚将上面的代码写入 try-catch 块..随着超时错误的到来,它会在我再次调用函数 downloadmailBox() 的地方捕获块。(有时脚本执行正确,有时会给出错误)。它会一次又一次地调用这个函数直到成功。可能它会在 2 或 3 次尝试内获得成功......所以通过这种方式,可以解决超时问题。

于 2012-11-01T11:48:15.233 回答