Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.

amsa-code/msgraph-sdk-java

 
 

Repository files navigation

Preview Microsoft Graph SDK for Java

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

Integrate the Microsoft Graph API into your Java application!

1. Installation

1.1 Install AAR via Gradle

Add the JCenter repository and a compile dependency for msicrosoft-graph to your project's build.gradle

repository {
    jcenter()
}

dependency {
    // Include the sdk as a dependency
    compile('com.microsoft.graph:1.0.+')

    // Include the gson dependency
    compile('com.google.code.gson:gson:2.3.1')
}

1.2 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 will need to ensure that ProGuard is enabled on your project. Otherwise, you will incur long build times for functionality that is not necessary 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 these steps.

2.2 Create an IAuthenticationProvider object

An instance of the GraphServiceClient class handles building requests, sending them to 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.

2.3 Get a GraphServiceClient object

Once you have set the correct application ID and url, you must get a GraphServiceClient object to make requests against the service. The SDK will store the account information for you, but when a user logs on for the first time, it will invoke UI to get the user's account information.

final IClientConfig mCLientConfig = DefaultClientConfig
                                        .createWithAuthenticationProvider(mAuthenticationProvider);

final IGraphServiceClient mClient = new GraphServiceClient
                                            .Builder()
                                            .fromConfig(mClientConfig)
                                            .buildClient();

3. Make requests against the service

Once you have an GraphServiceClient that is authenticated you can begin making calls against the service. The requests against the service look like our REST API.

Get the drive

To retrieve a user's drive:

graphClient
    .me()
    .drive()
    .buildRequest()
    .get(new ICallback<Drive>() {
  @Override
  public void success(final Drive result) {
    final String msg = "Found Drive " + result.id;
    Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT)
        .show();
  }
  ...
  // Handle failure case
});

For a general overview of how the SDK is designed, see overview.

4. Documentation

For a more detailed documentation see:

5. Issues

For known issues, see issues.

6. Contributions

The Microsoft Graph SDK is open for contribution. Please read how to contribute to this project here.

7. Supported Java Versions

The Microsoft Graph SDK for Java library is supported at runtime for Java 6+ and Android API revision 15 and greater.

8. License

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

9. Third Party Notices

Third Party Notices

About

Microsoft Graph SDK for Java

Resources

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Java 100.0%