使用Twilio api 5.6.1检索C#中的所有消息日志

时间:2017-08-17 17:07:09

标签: c# twilio

我需要从Twilio检索所有SMS日志。预计记录总数将很大,目标是大约10万条记录。在以前的库版本中,我可以执行以下操作来检索所有数据:

//Set up twilio account
var twilio = new TwilioRestClient(AccountSid, AuthToken);
//Set up a request
var request = new MessageListRequest(); 
//Get sms logs based on the request filter
MessageResult messages = twilio.ListMessages(request);

//Loop through all the page uri by Twilio to retrieve the messages
while (messages.NextPageUri != null)
{
    if (messages.Messages != null)
    {
        //Do something
    }
    if (messages.NextPageUri != null)
    {
        messages = twilio.GetNextPage<MessageResult>(messages);
    }
}

如何对当前的Twilio库版本执行相同的操作?

1 个答案:

答案 0 :(得分:2)

查看当前的Twilio REST API

// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var messages = MessageResource.Read();

        foreach (var message in messages)
        {
            Console.WriteLine(message.Body);
        }
    }
}