Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

msgraph-sdk-php

> 编程语言
Open source

Microsoft Graph Library for PHP.

668 stars0 likes0 views
WebsiteGitHub

About

Microsoft Graph Library for PHP.

Get started with the Microsoft Graph SDK for PHP

Install the SDK

Prerequisites

  • PHP 8.2 or later (see PHP supported versions)

You can install the PHP SDK with Composer by editing your composer.json file:

jsonc
{
    "require": {
        // x-release-please-start-version
        "microsoft/microsoft-graph": "^3.7.0"
        // x-release-please-end
    }
}

Get started with Microsoft Graph

Register your application

Register your application to use the Microsoft Graph API using Microsoft Azure Active Directory in your tenant's Active Directory to support work or school users for your tenant, or multiple tenants.

Create a Token Request Context

A Token Request Context contains the credentials used to authenticate requests. The SDK supports various contexts that align with OAuth 2.0 flows: client_credentials, authorization_code and on_behalf_of with support for secret-based and certificate-based client authentication.

Under the hood, the Token Request Context is passed to an authentication provider which fetches, caches and refreshes access tokens ensuring all requests are authenticated against the Microsoft Identity platform.

The following sample creates a TokenRequestContext that gets access without a user:

php
users()->byUserId('[userPrincipalName]')->get()->wait();
    echo "Hello, I am {$user->getGivenName()}";

} catch (ApiException $ex) {
    echo $ex->getError()->getMessage();
}

Note: The SDK is designed to make async requests by default. Operations (get(), post()...) return a Promise. To get the result, call wait() after the operation. Example: ->get()->wait();

Note that to calling me() requires a signed-in user and therefore delegated permissions (obtained using the authorization_code flow):

php
me()->get()->wait();
    echo "Hello, I am {$user->getGivenName()}";
} catch (ApiException $ex) {
    echo $ex->getError()->getMessage();
}

Documentation and resources

  • Documentation

  • Examples

  • Microsoft Graph website

Update Schedule

The Microsoft Graph PHP SDK is scheduled to be updated during the second and fourth week of each month

Upgrading

For detailed information on breaking changes, bug fixes and new functionality introduced during major upgrades, check out our Upgrade Guide

Develop

Run Tests

Run

bash
vendor/bin/phpunit

from the base directory.

Issues

View or log issues on the Issues tab in the repo.

Contribute

Please read our Contributing guidelines carefully for advice on how to contribute to this repo.

Copyright and license

Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPdevxengmicrosoftgraphsdk

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言