1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | """ 以下是使用 Python 的 requests 套件對 api_url 進行 GET 請求的程式碼, 並根據回應中的 next_page_token 繼續發送請求,直到沒有下一頁或下一頁為空: """ import requests API_KEY = "your_api_key" api_url = "your_api_url" params = {"API_KEY": API_KEY} next_page_token = None while True: if next_page_token: params["next_page_token"] = next_page_token response = requests.get(api_url, params=params) data = response.json()["data"] # 在這裡對回應的 data 做需要的處理 # ... if "next_page_token" in response.json(): next_page_token = response.json()["next_page_token"] else: break """ 請將 API_KEY 替換為你實際的 API 金鑰,並將 api_url 替換為你要請求的 API 的 URL。 在每次請求時,將 API 金鑰作為參數傳遞給 API。 如果回應中包含了 next_page_token,則將其作為參數傳遞到下一次請求中,以獲取下一頁的資料。持續發送請求直到沒有下一頁或下一頁為空。 請注意,你需要根據實際的 API 回應格式和需要進行相應的處理。 """ |
Direct link: https://paste.plurk.com/show/z5IZlrHTuCnMPEXSocOG