当我调用ListCalls时,CallResult对象说我有49页数据,每页50页。有没有办法使用Page或NextPageUri迭代C#中的页面?我注意到将Uri属性设置为NextPageUri不会刷新数据。感谢。
答案 0 :(得分:0)
您可以使用几个属性来实现抓取循环:
CallListRequest.Count - 记录您想要获得的数量。
CallListRequest.PageNumber - 包含您想要获取的数据的页面
CallResult.NumPages - 来自您的通话结果的总页数。
最后,您可以使用类似的内容从twilio API获取所有页面数据:
var client = new TwilioRestClient(accountSid, authToken);
var request = new CallListRequest();
request.Count = 1000;//1000 - is max value
request.PageNumber = 0;
var call = client.ListCalls(request);
List<TwillioCallRecord> callsToReturn = new List<TwillioCallRecord>();
if(call.Calls!=null){
callsToReturn.AddRange(call.Calls.Select(o=>new TwillioCallRecord(){CALL_TO = o.To, DATE_CREATED=o.DateCreated, DATE_UPDATED=o.DateUpdated, DIRECTION=o.Direction, DURATION = o.Duration, END_TIME=o.EndTime, FROM_NAME= person.FullName, PRICE=o.Price, STATUS=o.Status, START_TIME=o.StartTime}));
request.PageNumber++;
while(call.NumPages>request.PageNumber)
{
call = client.ListCalls(request);
callsToReturn.AddRange(call.Calls.Select(o=>new TwillioCallRecord(){CALL_TO = o.To, DATE_CREATED=o.DateCreated, DATE_UPDATED=o.DateUpdated, DIRECTION=o.Direction, DURATION = o.Duration, END_TIME=o.EndTime, FROM_NAME= person.FullName, PRICE=o.Price, STATUS=o.Status, START_TIME=o.StartTime}));
request.PageNumber++;
}
}