Cronofy - one API for all the calendars (Google, iCloud, Exchange, Office 365, Outlook.com)
To see this API wrapper in action see our sample app here
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.
Generate a link for a user to grant access to their calendars:
$redirect_uri = "http://yoursite.dev/oauth2/callback";
$cronofy = new Cronofy(array("client_id" => "clientId"));
$params = array(
'redirect_uri' => $redirect_uri,
'scope' => array('read_account','list_calendars','read_events','create_event','delete_event')
);
$auth = $cronofy->getAuthorizationURL($params);
The redirect URI 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:
$cronofy = new Cronofy(array(
"client_id" => "clientId",
"client_secret" => "ClientSecret"
));
$params = array(
'redirect_uri' => $redirect_uri,
'code' => $code
);
$token=$cronofy->request_token($params);
You should save the response's AccessToken
and RefreshToken
for later use.
Note that the exact same redirect URI must be passed to both methods for access to be granted.
Get a list of all the user's calendars:
$cronofy = new Cronofy(array(
"client_id" => "clientId",
"client_secret" => "ClientSecret",
"access_token" => "AccessToken",
"refresh_token" => "RefreshToken"
));
$calendar = $cronofy->list_calendars();
Get a list of all the user's events:
$cronofy = new Cronofy(array(
"client_id" => "clientId",
"client_secret" => "ClientSecret",
"access_token" => "AccessToken",
"refresh_token" => "RefreshToken"
));
$params = array(
'tzid' => 'Etc/UTC'
);
$events = $cronofy->read_events($params);
foreach($events->each() as $event){
// process event
}
To create/update an event in the user's calendar:
$cronofy = new Cronofy(array(
"client_id" => "clientId",
"client_secret" => "ClientSecret",
"access_token" => "AccessToken",
"refresh_token" => "RefreshToken"
));
$params = array(
'calendar_id' => 'calendarID',
'event_id' => 'event_test_12345679',
'summary' => 'test event 2',
'description' => 'some event data here',
'start' => '2015-12-07T09:00:00Z',
'end' => '2015-12-08T10:00:00Z'
);
$new_event = $cronofy->upsert_event($params);
To delete an event from user's calendar:
$cronofy = new Cronofy(array(
"client_id" => "clientId",
"client_secret" => "ClientSecret",
"access_token" => "AccessToken",
"refresh_token" => "RefreshToken"
));
$params = array(
'calendar_id' => 'calendarID',
'event_id' => 'EventID'
);
$delete = $cronofy->delete_event($params);
To delete an external event from a user's calendar:
$cronofy = new Cronofy(array(
"client_id" => "clientId",
"client_secret" => "ClientSecret",
"access_token" => "AccessToken",
"refresh_token" => "RefreshToken"
));
$params = array(
'calendar_id' => 'calendarID',
'event_uid' => 'EventUID'
);
$delete = $cronofy->delete_external_event($params);
To elevate a client's permissions for a user's calendar(s):
$cronofy = new Cronofy(array(
"client_id" => "clientId",
"client_secret" => "ClientSecret",
"access_token" => "AccessToken",
"refresh_token" => "RefreshToken"
));
$params = array(
'permissions' => array(
array(
'calendar_id' => 'calendarID_1',
'permission_level' => 'unrestricted'
),
array(
'calendar_id' => 'calendarID_2',
'permission_level' => 'unrestricted'
)
),
'redirect_uri' => 'http://yoursite.dev/elevate/callback'
);
$response = $cronofy->elevated_permissions($params);
To authorize a user's account using a service account:
$cronofy = new Cronofy(array(
"client_id" => "clientId",
"client_secret" => "ClientSecret",
"access_token" => "AccessToken",
"refresh_token" => "RefreshToken"
));
$params = array(
'email' => $email,
'callback_url' => $callback_url,
'scope' => array('read_account','list_calendars','read_events','create_event','delete_event')
);
$response = $cronofy->authorize_with_service_account($params);
Note: You will need to use a Service Account access token to perform this action.
To create a calendar for a user's account profile:
$cronofy = new Cronofy(array(
"client_id" => "clientId",
"client_secret" => "ClientSecret",
"access_token" => "AccessToken",
"refresh_token" => "RefreshToken"
));
$params = array(
'profile_id' => $account_profile_id,
'name' => $new_calendar_name
);
$response = $cronofy->create_calendar($params);
To use an alternative data center:
$cronofy = new Cronofy(array(
"client_id" => "clientId",
"client_secret" => "ClientSecret",
"access_token" => "AccessToken",
"refresh_token" => "RefreshToken",
"data_center" => "DataCenter"
));
curl -sS https://getcomposer.org/installer | php
php composer.phar install
vendor/bin/phpunit