Skip to content

ramsessanchez/msgraph-sdk-java-core

 
 

Repository files navigation

Microsoft Graph Core SDK for Java

Download Coverage Sonarcloud Status

Get started with the Microsoft Graph Core SDK for Java by integrating the Microsoft Graph API into your Java and Android application! You can also have a look at the Javadoc

Samples and usage guide

1. Installation

1.1 Install via Gradle

Add the repository and a compile dependency for microsoft-graph-core to your project's build.gradle:

repositories {
    mavenCentral()
}

dependencies {
    // Include the sdk as a dependency
    implementation 'com.microsoft.graph:microsoft-graph-core:2.0.8'
    // This dependency is only needed if you are using the TokenCrendentialAuthProvider
    implementation 'com.azure:azure-identity:1.3.1'
}

1.2 Install via Maven

Add the dependency in dependencies in pom.xml

<dependency>
    <!-- Include the sdk as a dependency -->
    <groupId>com.microsoft.graph</groupId>
    <artifactId>microsoft-graph-core</artifactId>
    <version>2.0.8</version>
    <!-- This dependency is only needed if you are using the TokenCrendentialAuthProvider -->
    <groupId>com.azure</groupId>
    <artifactId>azure-identity</artifactId>
    <version>1.3.1</version>
</dependency>

1.3 Enable ProGuard (Android)

The nature of the Graph API is such that the SDK needs quite a large set of classes to describe its functionality. You need to ensure that ProGuard is enabled on your project. Otherwise, you will incur long build times for functionality that is not necessarily relevant to your particular application. If you are still hitting the 64K method limit, you can also enable multidexing.

2. Getting started

2.1 Register your application

Register your application by following the steps at Register your app with the Azure AD v2.0 endpoint.

2.2 Create an IAuthenticationProvider object

An instance of the HttpClients class handles building client. To create a new instance of this class, you need to provide an instance of IAuthenticationProvider, which can authenticate requests to Microsoft Graph.

For an example of how to get an authentication provider, see choose a Microsoft Graph authentication provider.

2.3 Get a HttpClients object

You must get a HttpClients object to make requests against the service.

OkHttpClient client = HttpClients.createDefault(iAuthenticationProvider);

3. Make requests against the service

After you have a HttpClients that is authenticated, you can begin making calls against the service. The requests against the service look like our REST API.

3.1 Get the user's details

To retrieve the user's details

Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/me/").build();

client.newCall(request).enqueue(new Callback() {
	@Override
	public void onResponse(Call call, Response response) throws IOException {
		String responseBody = response.body().string();
		// Your processing with the response body 
	}
			
	@Override
	public void onFailure(Call call, IOException e) {
		e.printStackTrace();
	}
});

3.2 Get the user's drive

To retrieve the user's drive:

Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/me/drive").build();

client.newCall(request).enqueue(new Callback() {
	@Override
	public void onResponse(Call call, Response response) throws IOException {
		String responseBody = response.body().string();
		// Your processing with the response body 
	}
			
	@Override
	public void onFailure(Call call, IOException e) {
		e.printStackTrace();
	}
});

4. Issues

For known issues, see issues.

5. Contributions

The Microsoft Graph SDK is open for contribution. To contribute to this project, see Contributing.

6. Supported Java versions

The Microsoft Graph SDK for Java library is supported at runtime for Java 8 and Android API revision 26 or greater.

Android developers targeting lower android API levels can do so by enabling desugaring in their project.

7. License

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

8. Third-party notices

Third-party notices

About

Microsoft Graph SDK for Java - Core Library

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.3%
  • PowerShell 0.7%