Get started with the Microsoft Graph Core SDK for Java by integrating the Microsoft Graph API into your Java application!
During the preview we may make changes to the API, and other mechanisms of this library, which you will be required to take along with bug fixes or feature improvements. This may impact your application. An API change may require you to update your code. When we provide the General Availability release we will require you to update to the General Availability version within six months, as applications written using a preview version of library may no longer work.
Add the repository and a compile dependency for microsoft-graph-core to your project's build.gradle:
repository {
jcenter()
jcenter{
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
dependency {
// Include the sdk as a dependency
compile('com.microsoft.graph:microsoft-graph-core:0.1.0-SNAPSHOT')
}Add the dependency in dependencies in pom.xml
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-core</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
Add profiles in project to download Snapshot release binary:
<profiles>
<profile>
<id>allow-snapshots</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
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 Azure AD v2.0 endpoint.
An instance of the HttpClients class handles building client. To create a new instance of this class, you need to provide an instance of ICoreAuthenticationProvider, which can authenticate requests to Microsoft Graph.
You must get a HttpClients object to make requests against the service.
OkHttpClient client = HttpClients.createDefault(iCoreAuthenticationProvider);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.
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 Contributing.
Deepak Agrawal 💻 |
Nakul Sabharwal 💻📋 |
|---|
This project follows the all-contributors specification. Contributions of any kind are welcome!
The Microsoft Graph SDK for Java library is supported at runtime for Java 7+ and Android API revision 15 and greater.
Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license.