This client library is currently in private preview status. This means that:
- The API surface may change significantly.
- Non-blocking issues may be triaged at a slower pace.
- You may submit feedback through issues or PRs. You will have a better chance of your changes being implemented if they are submitted before public preview release.
- We do not define an SLA or support strategy for this library.
We welcome your feedback as we drive the quality of this to general availability.
Get started with the Microsoft Graph SDK for Java by integrating the Microsoft Graph API into your Java application!
Note
This package will not be available via Gradle until it is in public preview. You need to download the source and reference the package locally.
Add the JCenter repository and a compile dependency for microsoft-graph to your project's build.gradle:
repository {
jcenter()
}
dependency {
// Include the sdk as a dependency
compile('com.microsoft.graph:msgraph-sdk-java:1.0.+')
}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 GraphServiceClient class handles building requests, sending them to the 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 an example of authentication in a client application, see the MSGraph SDK Android MSA Auth for Android Adapter.
After you have set the correct application ID and URL, you must get a GraphServiceClient object to make requests against the service. The SDK stores the account information for you, but when a user signs in for the first time, it invokes the UI to get the user's account information.
IClientConfig clientConfig =
DefaultClientConfig.createWithAuthenticationProvider(mAuthenticationProvider);
IGraphServiceClient graphClient =
GraphServiceClient.builder()
.fromConfig(mClientConfig)
.buildClient();After you have a GraphServiceClient 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 drive:
graphClient
.me()
.drive()
.buildRequest()
.get(new ICallback<Drive>() {
@Override
public void success(final Drive result) {
System.out.println("Found Drive " + result.id);
}
...
// Handle failure case
});For a general overview of how the SDK is designed, see overview.
For more detailed documentation, see:
- Overview
- Extending the library
- Handling Open Types, PATCH support with
nullvalues - Collections
- Making custom requests
- Known issues
- Contributions
For known issues, see issues.
The Microsoft Graph SDK is open for contribution. To contribute to this project, see Contributing.
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.