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
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
// x-release-please-start-version
implementation 'com.microsoft.graph:microsoft-graph-core:3.3.1'
// x-release-please-end
// This dependency is only needed if you are using the TokenCredentialAuthProvider
implementation 'com.azure:azure-identity:1.11.0'
}
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>
<!--x-release-please-start-version-->
<version>3.3.1</version>
<!--x-release-please-end-->
<!-- This dependency is only needed if you are using the TokenCredentialAuthProvider -->
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.11.0</version>
</dependency>
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.
Register your application by following the steps at Register your app with the Microsoft Identity Platform.
Initialize an AuthenticationProvider
based on your preferred authentication flow
You must get an OkHttpClient object to make requests against the service.
Using the GraphClientFactory
, you can initialize an OkHttpClient
pre-configured for use with Microsoft Graph
OkHttpClient client = GraphClientFactory.create(authenticationProvider).build();
After you have an authenticated OkHttpClient
, you can begin making calls against the service. The requests against the service look like our REST API.
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();
}
});
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();
}
});
For known issues, see issues.
The Microsoft Graph SDK is open for contribution. To contribute to this project, see the Contributing guide.
The Microsoft Graph SDK for Java library is supported at runtime for Java 8 and Android API revision 26 or greater.
Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license.