I've made a link checker that works fine for all of the accounts in our MCC, except for 2.
Here is my code. It's simplified to work only over one account and does not return any results in spreadsheets or so. Just want to demonstrate the error that I'm receiving.
function main(){
var campaignIterator = AdWordsApp.campaigns().withCondition("Status != DELETED").get();
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
var campaignName = campaign.getName();
//-----------------------------------------------------------
var adGroupIterator = campaign.adGroups().withCondition("Status != DELETED").get();
while (adGroupIterator.hasNext()){
var adGroup = adGroupIterator.next();
//-----------------------------------------------------------
var adsIterator = adGroup.ads().get();
while (adsIterator.hasNext()) {
var ads = adsIterator.next();
Logger.log(ads.getId());
//-----------------------------------------------------------
if (ads.urls().getFinalUrl()){
var finalUrls = (ads.urls().getFinalUrl()) ;
var urlText = ads.urls().getFinalUrl();
var response = UrlFetchApp.fetch(finalUrls.split('?')[0], {followRedirects: false, muteHttpExceptions: true});
var rescheck = response.getResponseCode();
var together = rescheck + ' - ' + urlText ;
var errorUrls = [];
if (rescheck == 200 || rescheck == 301 ) {
continue;}
else {
errorUrls.push(together);
Logger.log(campaignName + ' - ' + adGroup.getName() + " - " /*+ ads.getHeadline() */+ " - " + errorUrls);
}
}
}
}
}
}
Is there a way in which I can setup a timeout in ms for a particular link. Like if the url does not return a response in 1000ms -> then continue with the next url?