Created
April 28, 2024 17:08
-
-
Save ryandhubbard/57c9b433c55f2953eb1c5a298e14b718 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fetch_paginated_data(url, params,headers): | |
all_results = [] | |
response = requests.get(url, headers=headers, params=params) | |
data = response.json() | |
# print(data) | |
all_results.extend(data['interactions']) | |
# print(all_results) | |
while 'next' in data['links']: | |
params = {} # Reset params for the next page | |
next_url = data['links']['next'] | |
response_next = requests.get(next_url, headers=headers) | |
data_next = response_next.json() | |
# print(data_next) | |
all_results.extend(data_next['interactions']) | |
data = data_next # Update data to the next page's data for the next iteration | |
# print(all_results) | |
return all_results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment