Showing posts with label php api. Show all posts
Showing posts with label php api. Show all posts

Tuesday 8 June 2021

Microsoft Graph API PHP

Microsoft Graph API PHP Tutorials

I am sharing some basic sample PHP code for Microsoft Graph API. May this will  helpful for someone.

For full reference, go to GIT URL:

PHP Framework Laravel Sample Code GIT URL:





















To start, you should have Outlook/Hotmail or any Microsoft Account.

First required to register App on Azure Active Directory. You can create App on Azure even if you have School or Organization account.

Graph API will generate Microsoft Authentication URL, where user will redirect and after successful login he will redirect back callback URL. Callback URL need to define in Azure App.

User can get Calendar events based on dates provided. User can create events on their Calendar.

Sharing Create Calendar Event using Microsoft Graph API.

<?php
// POST /me/events
$events_response = $graph->createRequest('POST', '/me/events')
    ->attachBody($newEvent)
    ->setReturnType(Model\Event::class)
    ->execute();


Get Calendar Events using Microsoft Graph API

<?php

$userEventsArr = $graph->createRequest('GET', $getEventsUrl)
// Add the user's timezone to the Prefer header
    ->addHeaders(array(
        'Prefer' => 'outlook.timezone="' . $userTimezone . '"',
    ))
    ->setReturnType(Model\Event::class)
    ->execute();

Create .ICS file using PHP code

Recently worked on creating a .ics file in PHP after a very long time, code so thought to share with everybody. Please find below the comple...