Skip to content

Getting Started

silaskenneth edited this page Apr 22, 2021 · 3 revisions

Getting started

Installation

The PHP SDK can be installed with Composer:

{
    "require": {
        "Microsoft/Graph": "^1.0"
    }
}

Register your application

Register your application to use Microsoft Graph API using one of the following supported authentication portals:

  • Microsoft Application Registration Portal (Recommended): Register a new application that authenticates using the v2.0 authentication endpoint. This endpoint authenticates both personal (Microsoft) and work or school (Azure Active Directory) accounts.
  • Microsoft Azure Active Directory: Register a new application in your tenant's Active Directory to support work or school users for your tenant, or multiple tenants.

Authenticate with the Microsoft Graph service

The Microsoft Graph SDK for PHP does not include any default authentication implementations. Instead, the user will want to authenticate with the library of their choice, or against the OAuth endpoint directly.

See the PHP Connect Sample for connecting with OAuth2.

Usage example

use Microsoft\Graph\Graph;

class UsageExample
{
    $accessToken = 'xxx';

    $graph = new Graph();
    $graph->setAccessToken($accessToken);

    $user = $graph->createRequest("GET", "/me")
                  ->setReturnType("User")
                  ->execute();

    echo "Hello, I am {$user->getGivenName()}.";
}