Integrate the Microsoft Graph API into your .NET project!
The Microsoft Graph .NET Client Library targets .NetStandard 1.1 and .Net Framework 4.5.
To install the client library via NuGet:
- Search for
Microsoft.Graph
in the NuGet Library, or - Type
Install-Package Microsoft.Graph
into the Package Manager Console.
Register your application to use Microsoft Graph API using one of the following supported authentication portals:
- Microsoft Application Registration Portal: Register a new application that works with Microsoft Account and/or organizational accounts using the unified V2 Authentication Endpoint.
- 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.
The Microsoft Graph .NET Client Library 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, and built-in DelegateAuthenticationProvider class to authenticate each request.
For more information on DelegateAuthenticationProvider
, see the library overview
The recommended library for authenticating against AAD is ADAL.
For an example of authenticating a UWP app using the V2 Authentication Endpoint, see the Microsoft Graph UWP Connect Library.
An instance of the GraphServiceClient class handles building requests,
sending them to Microsoft Graph API, and processing the responses. To create a
new instance of this class, you need to provide an instance of
IAuthenticationProvider
which can authenticate requests to Microsoft Graph.
For more information on initializing a client instance, see the library overview
Once you have completed authentication and have a GraphServiceClient, you can begin to make calls to the service. The requests in the SDK follow the format of the Microsoft Graph API's RESTful syntax.
For example, to retrieve a user's default drive:
var drive = await graphClient.Me.Drive.Request().GetAsync();
GetAsync
will return a Drive
object on success and throw a
ServiceException
on error.
To get the current user's root folder of their default drive:
var rootItem = await graphClient.Me.Drive.Root.Request().GetAsync();
GetAsync
will return a DriveItem
object on success and throw a
ServiceException
on error.
For a general overview of how the SDK is designed, see overview.
The following sample applications are also available:
- Microsoft Graph UWP Connect Sample
- Microsoft Graph UWP Snippets Sample
- Microsoft Graph MeetingBot sample for UWP
- Microsoft Graph Connect Sample for ASP.NET 4.6
- Microsoft Graph Snippets Sample for ASP.NET 4.6
- Microsoft Graph SDK Snippets Library for Xamarin.Forms
- Microsoft Graph Connect Sample for Xamarin Forms
- Microsoft Graph Meeting Manager Sample for Xamarin.Forms
- Microsoft Graph Property Manager Sample for Xamarin Native
Install NewtonSoft.Json first if you want to use a version greater than NewtonSoft.Json 6.0.1. For example, you'll need to install NewtonSoft.Json 9.0.1 first if you want to use this to library while targeting .Net Core with standard1.0.
Install System.Runtime.InteropServices.RuntimeInformation before you install Microsoft.Graph >=1.3 if you are having an issue updating the package for a Xamarin solution. You may need to updated references to Microsoft.NETCore.UniversalWindowsPlatform to >=5.2.2 as well.
To view or log issues, see issues.
- NuGet Package: https://www.nuget.org/packages/Microsoft.Graph
Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license