Reputation: 355
I am using Microsoft Graph and wish to give users the ability to add items to other users calendar though a an app we are writing.
I am using the following code, and can add to my own calendar.
$subject = 'Subject';
$body = 'Body content';
$start = time();
$end = time() + (30 * 60);
$startStr = date('Y-m-d', $start) . 'T' . date('H:i:s', $start) . ".0000000";
$endStr = date('Y-m-d', $end) . 'T' . date('H:i:s', $end) . ".0000000";
$data = array();
$data['subject'] = $subject;
$data['body'] = array();
$data['body']['content'] = $body;
$data['start'] = array();
$data['start']['dateTime'] = $startStr;
$data['start']['timeZone'] = 'UTC';
$data['end'] = array();
$data['end']['dateTime'] = $endStr;
$data['end']['timeZone'] = 'UTC';
echo 'subject: ' . $subject . '<br>';
echo 'body: ' . $body . '<br>';
echo 'start: ' . $startStr . '<br>';
echo 'end: ' . $endStr . '<br>';
$token = $_SESSION['access_token'];
$graph = new Graph();
$graph->setAccessToken($token);
$request = $graph->createRequest("post", '/me/calendar');
$request->attachBody($data);
$response = $request->execute();
When I change the createRequest to be
$request = $graph->createRequest("post", '/xxxx/calendar');
where xxxx is another user name, I am getting the following response
400 Bad Request
The permissions I am using to login are
profile openid email User.Read Calendars.ReadWrite Calendars.Read Calendars.Read.Shared Calendars.ReadWrite Calendars.ReadWrite.Shared
What else do I need to do in order to send items to another users calendar?
Upvotes: 1
Views: 792
Reputation: 3465
You are missing the permissions to act on another user's calendar. You have a few ways that you can do this:
The choice of which one is most appropriate depends on the requirements, how the application is structured, and who is the actor that is making a change.
Upvotes: 3