Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
440 views
in Technique[技术] by (71.8m points)

google apps script - Quickly reached the urlfetchapp() limit/day, below the theoric limit

I use the urlfetchapp() function within my google sheet and I got the 'exceeding limits' message, saying that I have exceeded the limit of use/day...

The limit is supposed to be 20k/day and I use it at a rate of around 14k/day... and worst, I got this after only around 1500 calls!

How can I get precision on this? Its pretty weird!

Thanks!

Here's my code:

var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('device_state'); // or whatever is the name of the sheet 


var numIterations = 9; // Number of iterations before reaching time limit (change accordingly)
  for (var i = 0; i < numIterations; i++) {

   var range30 = sheet.getRange("V2");
   var range31 = sheet.getRange("V3");
   var range32 = sheet.getRange("U5");
   

    var email = range30.getValue();
    var password = range31.getValue();
    var adresse = range32.getValue();
    

var url = "my url";
  var payload = {
    "email":email,
    "password":password
  };

  var opt = {
    "payload":payload,
    "method":"post",
    "followRedirects": false
  };  

  var response = UrlFetchApp.fetch(url, opt);
  

  var sessionDetails = response.getAllHeaders()['Set-Cookie'];

  opt2 = {
    "method" : "get",   
    "headers": {
      "Cookie": sessionDetails
    },
    "followRedirects" : false    
  };
  
  var response2 = UrlFetchApp.fetch("my other url", opt2);
  
  var text = response2.getContentText();
  

var searchstring = ['id=6004b7495e807f00351f773f','id=5fd24a5799cd7d0052f4208b','id=5fd24b2a9c457000352d666b','id=6004b776abf30d0023396566','id=5fd247c1fb7ee90015a32168','id=5fd24a9c37928d004016c131','id=6005f9c34423180040db0244'];


  for (var i = 0; i < 7; i++) {
    var index = text.search(searchstring[i]);
    if (index >= 0) {
      var pos = index + searchstring[i].length ;
      var rate = text.substring(pos +2, pos + 21);//6
      //rate = parseFloat(rate)
      //rate = 1/rate
      spreadsheet.getRange('W'+(i+20)).activate();
                       spreadsheet.getCurrentCell().setValue(rate)
      //return parseFloat(rate);
    }
  }

  //return response

SpreadsheetApp.flush();

var range0 = sheet.getRange("U20");
var range1 = sheet.getRange("V20");
var range2 = sheet.getRange("U21");
var range3 = sheet.getRange("V21");
var range4 = sheet.getRange("U22");
var range5 = sheet.getRange("V22");
var range6 = sheet.getRange("U23");
var range7 = sheet.getRange("V23");
var range8 = sheet.getRange("U24");
var range9 = sheet.getRange("V24");
var range10 = sheet.getRange("U25");
var range11 = sheet.getRange("V25");
var range12 = sheet.getRange("U26");




    if(sheet.getRange(20,27).getValue() == 1){
      var state = range0.getValue();
      var lieu = range1.getValue();
      var response = UrlFetchApp.fetch("https://graph-na04-useast2.api.smartthings.com/api/token/:?lieu="+lieu+"&state="+state);
                           Logger.log(response.getContentText());
    }

    if(sheet.getRange(21,27).getValue() == 1){
      var state = range2.getValue();
      var lieu = range3.getValue();
      var response = UrlFetchApp.fetch("https://graph-na04-useast2.api.smartthings.com/api/token/:?lieu="+lieu+"&state="+state);
                           Logger.log(response.getContentText());
    }

    if(sheet.getRange(22,27).getValue() == 1){
      var state = range4.getValue();
      var lieu = range5.getValue();
      var response = UrlFetchApp.fetch("https://graph-na04-useast2.api.smartthings.com/api/token/:?lieu="+lieu+"&state="+state);
                       Logger.log(response.getContentText());
    }

    if(sheet.getRange(23,27).getValue() == 1){
      var state = range6.getValue();
      var lieu = range7.getValue();
      var response = UrlFetchApp.fetch("https://graph-na04-useast2.api.smartthings.com/api/token/:?lieu="+lieu+"&state="+state);
                       Logger.log(response.getContentText());
    }

    if(sheet.getRange(24,27).getValue() == 1){
      var state = range8.getValue();
      var lieu = range9.getValue();
      var response = UrlFetchApp.fetch("https://graph-na04-useast2.api.smartthings.com/api/token/:?lieu="+lieu+"&state="+state);
                       Logger.log(response.getContentText());
    }

    if(sheet.getRange(25,27).getValue() == 1){
      var state = range10.getValue();
      var lieu = range11.getValue();
      var response = UrlFetchApp.fetch("https://graph-na04-useast2.api.smartthings.com/api/token/:?lieu="+lieu+"&state="+state);
                       Logger.log(response.getContentText());
    }

    if(sheet.getRange(26,27).getValue() == 1){
      var thermo = range12.getValue();
      var response = UrlFetchApp.fetch("https://graph-na04-useast2.api.smartthings.com/api/token/:?thermo="+thermo);
                       Logger.log(response.getContentText());
    }


   Utilities.sleep(1000 * 6); // Pause execution for X seconds
  }

}
question from:https://stackoverflow.com/questions/65944814/quickly-reached-the-urlfetchapp-limit-day-below-the-theoric-limit

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...