twilio - How can I use the C# TwilioRestClient and nextpageuri for paging -
i'm using twiliorestclient in following manner (this in loop obviously):
var currentpage = 0; private twiliorestclient mtwilioclient; var listrequest = new messagelistrequest() { = phonenumber, count = mmessagesperpage, datesent = datetime.today.subtract(timespan.fromdays(mdaystosearch)), datesentcomparison = comparisontype.greaterthanorequalto, pagenumber = currentpage++, }; var result = mtwilioclient.listmessages(listrequest);
this working fine me, i'm reading section paging through api resources
"the page parameter has been deprecated , may removed in future version of api. page parameter slower nextpageuri, , if new resources created while paging page parameter, consecutive pages may contain duplicate data."
and i'd start utilizing nextpageuri in case page depreciated in near future.
my question how can utilize nextpageuri via twilioresthelper (c#)? i've been unable find examples of , don't see appropriate method calls this.
so ended doing following:
private twiliorestclient mtwilioclient; var listrequest = new messagelistrequest() { = phonenumber, count = mmessagesperpage, datesent = datetime.today.subtract(timespan.fromdays(mdaystosearch)), datesentcomparison = comparisontype.greaterthanorequalto, }; var ret = mtwilioclient.listmessages(options); // ret.messages have first page of messages // next page of results if (ret.nextpageuri != null) { ret.next_page_uri = ret.nextpageuri.tostring().substring(11); } irestresponse result = mtwilioclient.execute(new restsharp.restrequest(ret.next_page_uri)); // classes provided twilio not line fields return in json reason, have massage data bit. result.content = cleanupjsoncontent(result.content); // deserialize json content class. var nextret = jsonconvert.deserializeobject<twilioresponse>(result.content); // set next_page_uri string value. can't use uri class since doesn't seem valid uri... nextret.next_page_uri = nextret.nextpageuri.tostring().substring(11); private string cleanupjsoncontent(string jsoncontent) { string ret = jsoncontent.replace("date_sent", "datesent"); ret = ret.replace("account_sid", "accountsid"); ret = ret.replace("date_created", "datecreated"); ret = ret.replace("date_updated", "dateupdated"); ret = ret.replace("num_segments", "numsegments"); ret = ret.replace("api_version", "apiversion"); ret = ret.replace("price_unit", "priceunit"); ret = ret.replace("error_code", "errorcode"); ret = ret.replace("error_message", "errormessage"); ret = ret.replace("first_page_uri", "firstpageuri"); ret = ret.replace("previous_page_uri", "previouspageuri"); ret = ret.replace("page_size", "pagesize"); ret = ret.replace("next_page_uri", "nextpageuri"); ret = ret.replace("num_pages", "numpages"); ret = ret.replace("last_page_uri", "lastpageuri"); return ret; }
Comments
Post a Comment