-
Notifications
You must be signed in to change notification settings - Fork 0
/
cronofyAPI.php
61 lines (56 loc) · 2.45 KB
/
cronofyAPI.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
include './db_connect.php';
function getAccessToken($code){
$data["code"]=$code;
$data_string = json_encode($data);
$ch = curl_init('https://api.cronofy.com/oauth/token');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: '. strlen($data_string)));
$result = curl_exec($ch);
$data=json_decode($result,true);
return $data["access_token"];
}
function getCalendar($access_token){
$curl = curl_init('https://api.cronofy.com/v1/calendars');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$access_token));
$result = curl_exec($curl);
return $result;
}
function createEvent($event,$desc,$start,$end){
$data=array("event_id"=> "testing","summary"=> $event,"description"=> $desc,"start"=> $start,"end"=> $end);
$d=json_encode($data);
$ch = curl_init('https://api.cronofy.com/v1/calendars/'.$_SESSION['cal_id'].'/events');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $d);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$_SESSION['access_token'],
'Content-Type: application/json',
'Content-Length: ' . strlen($d))
);
curl_exec($ch);
if(curl_getinfo($ch ,CURLINFO_HTTP_CODE)=="202")
return true;
return false;
}
function deleteAllEvents(){
$data=array("delete_all"=>"true");
$d=json_encode($data);
$ch = curl_init('https://api.cronofy.com/v1/events/');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_POSTFIELDS, $d);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$_SESSION['access_token'],
'Content-Type: application/json;charset=utf-8',
'Content-Length: ' . strlen($d)),
);
curl_exec($ch);
if(curl_getinfo($ch ,CURLINFO_HTTP_CODE)=="202")
return true;
return false;
}
?>