Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ways to access Microsoft Graph API

I am trying to access Microsoft Graph API using the following code in Java :-

    String url_str = "https://graph.microsoft.com/v1.0/users/";
    String access_token = getAccessToken();
    url = new URL(url_str);
    con = ( HttpURLConnection )url.openConnection();
    con.setDoInput(true);
    con.setDoOutput(true);
    con.setUseCaches(false);
    con.setRequestMethod("GET");
    con.setRequestProperty("Authorization", access_token);
    con.setRequestProperty("Accept","application/json");
    con.connect();

    br = new BufferedReader(new InputStreamReader( con.getInputStream() ));
    String str = null;
    String line;
    while((line = br.readLine()) != null) {
        str += line;
    }
    System.out.println(str);
} catch (Exception e) {
    e.printStackTrace();
}

Currently I am getting JSON String which i will need to parse further. All I want to know is there any other way which will reduce the pain of deserialization or something more better.

like image 507
Batman22 Avatar asked Feb 14 '18 18:02

Batman22


Video Answer


2 Answers

Update on Martin answer, Java SDK is released and available for public preview :- https://github.com/microsoftgraph/msgraph-sdk-java.

like image 87
Batman22 Avatar answered Oct 12 '22 04:10

Batman22


Im not aware of any Java SDK for Microsoft Graph. However, you can use jsonutil to generate your java objects which will reduce at least some work.

Edit: As mentioned by Pranay, a Java SDK is released, you should use this instead.

like image 31
Martin Brandl Avatar answered Oct 12 '22 02:10

Martin Brandl