Q: Error when doing recursion in Python I use the below function to get all groups in our facebook community. I set the page limit as 20 (n) to get all groups in one page and then it recursively goes to the next page. But there are close to 1000 groups in our community. With 20 pages and 25 groups in one page, I get close to 500 groups. If I increase the page limit, recursion throws an error that "next pointer cannot handle".
Has anyone come across this type of error? Did you follow any steps to overcome it? Any suggestions would be great !!
TOKEN = "kjahfdsk1232415"
def getGroups(n,groups,after=None):

      if n==20:
          return groups
      headers = {'Authorization': 'Bearer ' + TOKEN}

      params = "?fields=feed.since(" + "1493658316"  + ").limit(1),name,updated_time&"

      params += "&limit=" + 10

      if after:
          #print (after)
          params += "?limit=50&after=" + after

      graph_url = GRAPH_URL_PREFIX + "community" + GROUPS_SUFFIX + params

      result = requests.get(graph_url, headers=headers)
      result_json = json.loads(result.text)

      if "data" in result_json:
          for group_obj in result_json["data"]:
              groups.append(group_obj)

      n = n + 1
      if 'paging' in result_json:
          getGroups(n,groups,after=result_json["paging"]["next"])
      return groups

