Skip to content

skyhoshi/msgraph-sdk-dotnet-core

 
 

Repository files navigation

Microsoft Graph .NET Core Client Library

Build Status NuGet Version

Integrate the Microsoft Graph API into your .NET project!

The Microsoft Graph .NET Core Client Library contains core classes and interfaces used by Microsoft.Graph Client Library to send native HTTP requests to Microsoft Graph API. The core client library targets .NetStandard 1.1 and .Net Framework 4.5.

Installation via NuGet

To install the client library via NuGet:

  • Search for Microsoft.Graph.Core in the NuGet Library, or
  • Type Install-Package Microsoft.Graph.Core into the Package Manager Console.

Getting started

1. Register your application

Register your application to use Microsoft Graph API by following the steps at Register your application with the Microsoft identity platform.

2. Authenticate for the Microsoft Graph service

The Microsoft Graph .NET Client Library supports the use of TokenCredential classes in the Azure.Identity library.

You can read more about available Credential classes here and examples on how to quickly setup TokenCredential instances can be found here.

The recommended library for authenticating against Microsoft Identity (Azure AD) is MSAL.

For an example of authenticating a UWP app using the V2 Authentication Endpoint, see the Microsoft Graph UWP Connect Library.

3. Create a HttpClient object with an authentication provider

You can create an instance of HttpClient that is pre-configured for making requests to Microsoft Graph APIs using GraphClientFactory.

HttpClient httpClient = GraphClientFactory.Create( version: "beta");

For more information on initializing a client instance, see the library overview

4. Make requests to the graph

Once you have an authenticated HttpClient, you can begin to make calls to the service. The requests to the service follows our REST API syntax.

For example, to retrieve a user's default drive:

HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "me/drive");
HttpResponseMessage response = await httpClient.SendAsync(requestMessage);
if (response.IsSuccessStatusCode)
{
    string jsonResponse = await response.Content.ReadAsStringAsync();
}

To get the current user's root folder of their default drive:

HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "me/drive/root");
HttpResponseMessage response = await httpClient.SendAsync(requestMessage);
if (response.IsSuccessStatusCode)
{
    string jsonResponse = await response.Content.ReadAsStringAsync();
}

Documentation and resources

Notes

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.

Issues

To view or log issues, see issues.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Other resources

Building library locally

If you are looking to build the library locally for the purposes of contributing code or running tests, you will need to:

  • Have the .NET Core SDK (> 1.0) installed
  • Run dotnet restore from the command line in your package directory
  • Run nuget restore and msbuild from CLI or run Build from Visual Studio to restore Nuget packages and build the project

License

Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license. See Third Party Notices for information on the packages referenced via NuGet.

About

The core Microsoft Graph client library for .Net. (Microsoft.Graph.Core)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 97.7%
  • PowerShell 2.3%