Skip to content

tariqhamid/cronofy-csharp

 
 

Repository files navigation

Cronofy

Cronofy - one API for all the calendars (Google, iCloud, Exchange, Office 365, Outlook.com)

Installation

The Cronofy .NET SDK is available as a Nuget package, to install run the following command in the Package Manager Console

Install-Package Cronofy

More info is available on nuget

Usage

In order to use the Cronofy API you will need to create a developer account.

From there you can use your Calendar Sandbox to access your own calendars, or you can create an OAuth application to obtain an OAuth client_id and client_secret to be able to use the full API.

Authorization

API documentation

Generate a link for a user to grant access to their calendars:

const string CallbackUrl = "http://yoursite.dev/oauth2/callback";

var cronofy = new CronofyOAuthClient("clientId", "clientSecret");
var authorizationUrl = cronofy.GetAuthorizationUrlBuilder(CallbackUrl).Build();

The callback URL is a page on your website that will handle the OAuth 2.0 callback and receive a code parameter. You can then use that code to retrieve an OAuth token granting access to the user's Cronofy account:

var token = cronofy.GetTokenFromCode(code, CallbackUrl);

You should save the response's AccessToken and RefreshToken for later use.

Note that the exact same callback URL must be passed to both methods for access to be granted.

List calendars

API documentation

Get a list of all the user's calendars:

var cronofy = new CronofyAccountClient(accessToken);
var calendars = cronofy.GetCalendars();

Read events

API documentation

Get a list of events from the user's calendars:

var cronofy = new CronofyAccountClient(accessToken);
var events = cronofy.GetEvents();

Note that the SDK handles iterating through the pages on your behalf.

Create or update events

API documentation

To create/update an event in the user's calendar:

var cronofy = new CronofyAccountClient(accessToken);

var eventBuilder = new UpsertEventRequestBuilder()
    .EventId("uniq-id")
    .Summary("Event summary")
    .Description("Event description")
    .Start(2015, 10, 20, 17, 00)
    .End(2015, 10, 20, 17, 30)
    .TimeZoneId("Europe/London")
    .Location("Meeting room");

cronofy.UpsertEvent(calendarId, eventBuilder);

Delete events

API documentation

To delete an event from user's calendar:

var cronofy = new CronofyAccountClient(accessToken);
cronofy.DeleteEvent(calendarId, "uniq-id");

Links

Packages

No packages published

Languages

  • C# 99.8%
  • Other 0.2%