I'm using https://github.com/twilio/twilio-python and have read through the documentation including https://www.twilio.com/docs/api/rest/response#response-formats-list-paging-information.
I can't seem to find the method to retrieve the next page from a large list. I'm using the following code to retrieve the initial list but don't know how to retrieve the nextpageuri and then retrieve the next page.
client = TwilioRestClient(twilioAccount, twilioToken)
messages = client.messages.list(
to="+15162047575",
# to="+15167217331",
after=date(2014,5,7),
PageSize=50)
I'm using Twilio 3.6.4 and 3.5.1 with the latest version of the python helper.
I finally found the answer (and I assume it's ok for me to self answer ...)
The Twilio helper library (at least the python helper) does not expose the nextpageuri directly (which explains why I couldn't find a method or property to access nextpageuri).
Although the paging information on the Twilio site describes methods for paging using nextpageuri, the helper library utilizes an iter() method.
So rather than use the code I posted in my question and then loop through 'messages', you can use:
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
for message in client.messages.iter():
# code to process message
From the python helper documentation (not the Twilio Rest API documentation):
Sometimes you’d like to retrieve all records from a list resource. Instead of manually paging over the resource, the resources.ListResource.iter method returns a generator. After exhausting the current page, the generator will request the next page of results.
Here are some references:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With