Sample Code using the Rtm class

Here's a code sample that shows how to use the Rtm class ("layer 2", or "high level" of the IronCow API).

Rtm rtm = new Rtm("your api key", "your shared secret");
rtm.AuthToken = GetAuthenticationToken(); //TODO: get an authentication token

// Have fun!
foreach (TaskList list in rtm.TaskLists)
{
    Console.WriteLine(list.Name);
    foreach (Task task in list.Tasks)
    {
        Console.WriteLine("   - {0}", task.Name);
    }
}


To get an authentication token, check the authentication documentation on Remember The Milk's website. The Rtm.CheckToken(), Rtm.GetAuthenticationUrl(), Rtm.GetFrob() and Rtm.GetToken() will help you get through the several steps needed for this. But basically, it goes something like this:

IronCow.Rtm rtm = new IronCow.Rtm(ApiKey, SharedSecret);
string frob = rtm.GetFrob();
System.Diagnostics.Process.Start(rtm.GetAuthenticationUrl(frob, IronCow.AuthenticationPermissions.Write));   // Run the default browser to open the "authenticate" page on RTM's website.
Console.WriteLine("Press enter to continue after you have authenticated in the browser...");
Console.ReadLine();
rtm.AuthToken = rtm.GetToken(frob);    // Get the auth-token with the same frob we got earlier.
Console.WriteLine("Successfully authenticated! Got token: " + rtm.AuthToken);


The TaskList and Task objects, along with the other ones you'll get through the Rtm class, are always in sync with the server. If you set their name property, or add or remove elements to them, the appropriate requests are sent behind the scenes.

Last edited Sep 2, 2010 at 11:14 PM by ludovic_chabant, version 3

Comments

No comments yet.