mbdax/microsoftgraphbundle

Symfony2 bundle for API Micrososft

dev-master 2017-05-11 11:41 UTC

This package is not auto-updated.

Last update: 2024-04-27 23:57:01 UTC


README

Installation

Add MicrosoftGraphBundle to your project

The recommended way to install the bundle is through Composer.

$ composer require 'mbdax/microsoftgraphbundle:dev-master'

Configuration

You have to configure your api:

    microsoft_graph:
        client_id: "%client_id%"
        client_secret: "%client_secret%"
        redirect_uri: "name of your redirect route"
        time_zone: "" # your prefered timezone default UTC
        version: "" version of API GRAPH: #1.0 or beta,  deafault 1.0
        stateless: true # if false, the state will stored in session
        scopes:  # for more details https://developer.microsoft.com/en-us/graph/docs/authorization/permission_scopes
            - openid
            - offline_access
            #- ...
            

Get token from Office 365 | API Graph

    // Get client service 
    $client= $this->get('microsoft_graph.client');
    try{
        /*
         if you have a refresh token then  the token will refresh 
         */
        $client->getNewToken();

    }catch(\Exception $ex){
        // else 
        $client->redirect(); // redirect to office 365 authentication page
    }

Example get events from outlook calendar

// Get calendar service 
    $calendar= $this->get('microsoft_graph.calendar');
            
//Get a collection of Microsoft\Graph\Model\Event
    $startTime = new DateTime("first day of this month");
    $endTime = new DateTime("first day of next month");
    
    $events = $calendar->getEvents($startTime,$endTime);

//Get a  Microsoft\Graph\Model\Event
    $id='...'
    $event= $calendar->getEvent($id);
     

Create an event

         
//  create Microsoft\Graph\Model\Event and set properties
 $newEvent= new Microsoft\Graph\Model\Event();              
 $start= $calendar->getDateTimeTimeZone(new \DateTime('Now next minute'));
 $end= $calendar->getDateTimeTimeZone(new \DateTime('Now next hour'));
 
 $newEvent->setSubject('Controller Test Token');
 $newEvent->setStart($start);
 $newEvent->setEnd( $end);     

 $event= $calendar->addEvent( $newEvent);
  
        dump($event);

Update an event

    $id='...'
    $updateEvent= new Microsoft\Graph\Model\Event(); 
    $updateEvent->setId($id);
    $updateEvent->setSubject("I Forgot The Eggs!");
    $event= $calendar->updateEvent( $updateEvent);

Delete an event

    $id='...'
    $response= $calendar->deleteEvent( $id);
    dump($response->getStatus()==204?"Event deleted":$response);

TODOS

Abstract Entities Documentation