2014-10-29 60 views
1

當我調用ListCalls時,CallResult對象表示我有49頁數據,每頁50個。有沒有辦法在頁面或NextPageUri中遍歷C#中的頁面?我注意到將Uri屬性設置爲NextPageUri不會刷新數據。謝謝。Twilio API分頁C#中的CallResult對象

回答

0

有一對夫婦,你可以用它來實現抓循環特性:

  1. CallListRequest.Count - 記錄算你想要得到。

  2. CallListRequest.PageNumber - 從您的通話結果頁面的總數 - 數據你想獲得

  3. 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++; 
        } 
      }