|
1 | | -# Microsoft Graph Core SDK for Java |
| 1 | +# Microsoft Graph Core SDK for Java |
| 2 | + |
| 3 | +[  ](https://bintray.com/microsoftgraph/Maven/microsoft-graph/_latestVersion) |
| 4 | + |
| 5 | + |
| 6 | +Get started with the Microsoft Graph Core SDK for Java by integrating the [Microsoft Graph API](https://graph.microsoft.io/en-us/getting-started) into your Java application! |
| 7 | + |
| 8 | +## 1. Installation |
| 9 | + |
| 10 | +### 1.1 Install via Gradle |
| 11 | + |
| 12 | +Add the repository and a compile dependency for `microsoft-graph` to your project's `build.gradle`: |
| 13 | + |
| 14 | +```gradle |
| 15 | +repository { |
| 16 | + jcenter() |
| 17 | +} |
| 18 | +
|
| 19 | +dependency { |
| 20 | + // Include the sdk as a dependency |
| 21 | + compile('com.microsoft.graph:microsoft-graph-core:0.1.0-SNAPSHOT') |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +### 1.2 Install via Maven |
| 26 | +Add the dependency in `dependencies` in pom.xml |
| 27 | +```dependency |
| 28 | +<dependency> |
| 29 | + <groupId>com.microsoft.graph</groupId> |
| 30 | + <artifactId>microsoft-graph-core</artifactId> |
| 31 | + <version>0.1.0-SNAPSHOT</version> |
| 32 | +</dependency> |
| 33 | +``` |
| 34 | + |
| 35 | +Add `profiles` in `project` to download Snapshot release binary: |
| 36 | +``` |
| 37 | +<profiles> |
| 38 | + <profile> |
| 39 | + <id>allow-snapshots</id> |
| 40 | + <activation> |
| 41 | + <activeByDefault>true</activeByDefault> |
| 42 | + </activation> |
| 43 | + <repositories> |
| 44 | + <repository> |
| 45 | + <id>snapshots-repo</id> |
| 46 | + <url>https://oss.sonatype.org/content/repositories/snapshots</url> |
| 47 | + <releases> |
| 48 | + <enabled>false</enabled> |
| 49 | + </releases> |
| 50 | + <snapshots> |
| 51 | + <enabled>true</enabled> |
| 52 | + </snapshots> |
| 53 | + </repository> |
| 54 | + </repositories> |
| 55 | + </profile> |
| 56 | +</profiles> |
| 57 | +``` |
| 58 | + |
| 59 | +### 1.3 Enable ProGuard (Android) |
| 60 | +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](https://developer.android.com/studio/build/shrink-code.html) 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](https://developer.android.com/studio/build/multidex.html). |
| 61 | + |
| 62 | +## 2. Getting started |
| 63 | + |
| 64 | +### 2.1 Register your application |
| 65 | + |
| 66 | +Register your application by following the steps at [Register your app with the Azure AD v2.0 endpoint](https://developer.microsoft.com/en-us/graph/docs/concepts/auth_register_app_v2). |
| 67 | + |
| 68 | +### 2.2 Create an IAuthenticationProvider object |
| 69 | + |
| 70 | +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. |
| 71 | + |
| 72 | +For an example of authentication in a client application, see the [MSGraph SDK Android MSA Auth for Android Adapter](https://github.com/microsoftgraph/msgraph-sdk-android-msa-auth-for-android-adapter). |
| 73 | + |
| 74 | +### 2.3 Get a HttpClient object |
| 75 | +You must get a **HttpClient** object to make requests against the service. |
| 76 | + |
| 77 | +```java |
| 78 | +CloseableHttpClient httpClient = HttpClients.createDefault(authenticationProvider); |
| 79 | +``` |
| 80 | + |
| 81 | +## 3. Make requests against the service |
| 82 | + |
| 83 | +After you have a HttpClient that is authenticated, you can begin making calls against the service. The requests against the service look like our [REST API](https://developer.microsoft.com/en-us/graph/docs/concepts/overview). |
| 84 | + |
| 85 | +### 3.1 Get the user's drive |
| 86 | + |
| 87 | +To retrieve the user's drive: |
| 88 | + |
| 89 | +```java |
| 90 | +HttpGet httpget = new HttpGet("https://graph.microsoft.com/v1.0/me/"); |
| 91 | +try{ |
| 92 | + HttpResponse response = httpclient.execute(httpget); |
| 93 | + //... |
| 94 | +}catch(IOException e){ |
| 95 | +//Handle exception |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +## 4. Issues |
| 100 | + |
| 101 | +For known issues, see [issues](https://github.com/MicrosoftGraph/msgraph-sdk-java-core/issues). |
| 102 | + |
| 103 | +## 5. Contributions |
| 104 | + |
| 105 | +The Microsoft Graph SDK is open for contribution. To contribute to this project, see [Contributing](https://github.com/microsoftgraph/msgraph-sdk-java/blob/master/CONTRIBUTING.md). |
| 106 | + |
| 107 | +<!-- ALL-CONTRIBUTORS-LIST:START --> |
| 108 | +<!-- prettier-ignore --> |
| 109 | +[<img src="https://avatars2.githubusercontent.com/u/3197588?v=4" width="100px;"/><br /><sub><b>Deepak Agrawal</b></sub>](https://github.com/deepak2016)<br />[💻](https://github.com/microsoftgraph/msgraph-sdk-java/commits?author=deepak2016 "Code") |
| 110 | +<!-- ALL-CONTRIBUTORS-LIST:END --> |
| 111 | + |
| 112 | +This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome! |
| 113 | + |
| 114 | +## 6. Supported Java versions |
| 115 | +The Microsoft Graph SDK for Java library is supported at runtime for Java 7+ and [Android API revision 15](http://source.android.com/source/build-numbers.html) and greater. |
| 116 | + |
| 117 | +## 7. License |
| 118 | + |
| 119 | +Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the [MIT license](LICENSE). |
| 120 | + |
| 121 | +## 8. Third-party notices |
| 122 | + |
| 123 | +[Third-party notices](THIRD%20PARTY%20NOTICES) |
0 commit comments