I am trying to access the following url via Microsoft Graph Api :- https://graph.microsoft.com/v1.0/me I have used the code given below found on stackoverflow which should ideally give me JSON. But I am getting exception while running the code :-
try {
String url_str = "https://graph.microsoft.com/v1.0/me";
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();
}
I am getting valid access token. But I am getting following exception:-
java.io.FileNotFoundException: https://graph.microsoft.com/v1.0/me
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at com.controller.MicrosoftGraphController.getUserInfo(MicrosoftGraphController.java:50)
at com.controller.MicrosoftGraphController.main(MicrosoftGraphController.java:82)
I tried searching but haven't found anything related to this particular issue. Any Suggestions? Thanks!
404over the wire.