Twilio API在C#中调用CallResult对象

时间:2014-10-29 17:40:08

标签: c# twilio

当我调用ListCalls时,CallResult对象说我有49页数据,每页50页。有没有办法使用Page或NextPageUri迭代C#中的页面?我注意到将Uri属性设置为NextPageUri不会刷新数据。感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用几个属性来实现抓取循环:

  1. CallListRequest.Count - 记录您想要获得的数量。

  2. CallListRequest.PageNumber - 包含您想要获取的数据的页面

  3. CallResult.NumPages - 来自您的通话结果的总页数。

  4. 最后,您可以使用类似的内容从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++;
                      }
                 }