-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-msgraph.php
66 lines (50 loc) · 2.01 KB
/
test-msgraph.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
62
63
64
65
66
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Include the Microsoft Graph classes
use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;
// THIS INFORMATION YOU GET AFTER REGISTRATION OF A NEW AZURE APPLICATION
$tenantId="YOUR TENTANT ID FROM YOUR MS TENANT";
$clientId="YOUR CLIENT ID FROM YOUR APPLICATION";
$clientSecret="YOUR CLIENT SECRET FROM YOUR APPLICATION";
//GET A CONNECTION TO MS
$guzzle = new \GuzzleHttp\Client();
$url = 'https://login.microsoftonline.com/' . $tenantId . '/oauth2/token?api-version=1.0';
$token = json_decode($guzzle->post($url, [
'form_params' => [
'client_id' => $clientId,
'client_secret' => $clientSecret,
'resource' => 'https://graph.microsoft.com/',
'grant_type' => 'client_credentials',
],
])->getBody()->getContents());
$accessToken = $token->access_token;
//Print out your accessTOKEN
echo "AccessToken:".$accessToken."\n\n\n";
// GET A CONNECTION TO MS GRAPH
$graph = new Graph();
$graph->setAccessToken($accessToken);
//MY events:
$events = $graph->createRequest("GET", "/me/events",)
->addHeaders(['Prefer' => 'outlook.timezone="Europe/Berlin"']) //Here you can insert the Timezone for Events
->setReturnType(Model\Event::class)
->execute();
//Events of other users
/*
$events = $graph->createRequest("GET", "/users/Email Address of the user/events",)
->addHeaders(['Prefer' => 'outlook.timezone="Europe/Berlin"']) //Here you can insert the Timezone for Events
->setReturnType(Model\Event::class)
->execute();
*/
print_r($events);
foreach ($events as $item) {
$id = $item->getId();
$start = ($item->getStart()->getDateTime());
$end = ($item->getend()->getdatetime());
$author = $item->getOrganizer()->getEmailaddress()->getname();
$subject = $item->getSubject();
echo $subject."\n";
echo $author."\n";
echo $start."-->".$end;
}
?>