Get started with the Microsoft Graph SDK for PHP
This SDK is currently in preview. Please continue to provide feedback as we iterate towards a production-supported library.
Get started with the PHP Connect Sample
If you want to play around with the PHP library, you can get up and running quickly with the PHP Connect Sample. This sample will start you with a little Laravel project that helps you with registration, authentication, and making a simple call to the service.
Install the SDK
You can install the PHP SDK with Composer.
{
"require": {
"microsoft/microsoft-graph": "0.1.*"
}
}
Get started with Microsoft Graph
Register your application
Register your application to use the Microsoft Graph API by 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, you can authenticate with the library of your choice, or against the OAuth endpoint directly.
To connect with Oauth2, see the PHP Connect Sample.
Call Microsoft Graph
The following is an example that shows how to call Microsoft Graph.
use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;
class UsageExample
{
public function run()
{
$accessToken = 'xxx';
$graph = new Graph();
$graph->setAccessToken($accessToken);
$user = $graph->createRequest("GET", "/me")
->setReturnType(Model\User::class)
->execute();
echo "Hello, I am $user->getGivenName() ";
}
}Develop
Run Tests
Run
vendor/bin/phpunit --exclude-group functionalfrom the base directory.
The set of functional tests are meant to be run against a test account. Currently, the tests to do not restore state of the account.
Documentation and resources
Issues
View or log issues on the Issues tab in the repo.
Copyright and license
Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license.