I am using Email Audi API to download user's mailbox in encrypted form..When i write code into google script and tried to run then it gives error 504 : Timeout error.. When i did this using OAuth playground then i succeed to download mailbox..So please give me some suggestion to resolve this problem.
Code :
function downloadMailBox(user){
var user='[email protected]'
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'
};
}
I found one solution for this...I just wrote above code into try-catch block..As timeout error comes, it goes to catch block where i am calling above function downloadmailBox() again.(sometimes script executes properly and sometimes gives error).It will call this function again and again till get success. probably it gets success within 2 or 3 attempts...So by doing this way, timeout problem can be resolve.