简体   繁体   中英

Why do I keep getting "Exception: Service invoked too many times in a short time: groups read. Try Utilities.sleep(1000) between calls."?

I just ran a sample code from Apps Script tutorial:

https://developers.google.com/apps-script/reference/groups/group#getGroups()

(I have commented out the loop part to make the problem clear.)

function listGroupMembers() {
  var GROUP_EMAIL = "a-group@in.mydomain";
  var group = GroupsApp.getGroupByEmail(GROUP_EMAIL);
  Utilities.sleep(10000);

  var childGroups = group.getGroups();
  console.log("Group " + GROUP_EMAIL + " has " + childGroup.length + " groups:");

  /* comment out the loop to make the problem clear.
  for (var i = 0; i < childGroups.length; i++) {
    var childGroup = childGroups[i];
    console.log(childGroup.getEmail());
  }
  */

}

But I keep getting the following exception:

Exception: Service invoked too many times in a short time: groups read. Try Utilities.sleep(1000) between calls. 
listGroupMembers    @ test.gs:6

Even if I run a script for the first time in the last 24 hours, I get this exception. Any advice?

It must be the limitation of getGroups() .

I tested a group with changing the number of child groups. Below is the result.

  • Num of Group: 1 to 7: Always success.
  • Num of Group: 8: Sometimes fail.
  • Num of Group: 9: Sometimes success.
  • Num of Group: 10: Always fail.

Looks like we can use getGroups() only when the number child groups is 7 or less.

Possible Issues:

  • There is a lot of calls to your getEmail() . Even if the function was executed once, consecutive childGroup.getEmail() was called many times inside the loop in a short duration of time going past the quota.
  • Groups read shows a limit of 2000/10000 (depending on your account) per day. If yours go beyond that limit, then it reached the quota. If not, then maybe it reached the per minute/hour quota (haven't found the documentation how many is it per minute/hour)

团体

Possible steps you could take:

  • Place your sleep function inside the loop so it pauses every loop, thus reducing the calls done per minute/hour. See if that alleviates the problem.
  for (var i = 0; i < childGroups.length; i++) {
    var childGroup = childGroups[i];
    console.log(childGroup.getEmail());
    Utilities.sleep(10000);
  }
  • If it didn't, check the length of your childGroups . If that goes beyond the limit, try to limit your loop into 1950/9950 if it fixes the problem. If that fixes it, then it is confirmed that your function fails because of the quota being reached.
  for (var i = 0; i < 1950; i++) { // or 9950, depending on the account
    var childGroup = childGroups[i];
    console.log(childGroup.getEmail());
    Utilities.sleep(10000);
  }

Reference:

i have the same issue? any news or solution? i think it is a bug because i didnt exceed the quota

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM