locked
One Drive - Signing users in with REST RRS feed

  • Question

  • Hi,

    I am trying to integrate my one drive account using simple java application.
    My first step is  Signing users in with REST.  When I use Advanced Rest Client that comes with chrome extensions to consume the rest web service (https://login.live.com/oauth20_authorize.srf?client_id=CLIENT_ID&scope=wl.signin&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080&client_secret=CLIENT_SECRET) , I get a response which is different from when I consume the service from my java code.

    The java code I am using is as follows :

    URL url = new URL("https://login.live.com/oauth20_authorize.srf?client_id=000000004015D02E&scope=wl.signin&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080&client_secret=-7hIh153MP8MxDsT9RuqRZM1XpKDlVKD");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("GET");
     if (conn.getResponseCode() != 200) {
        System.out.println("****************** Failed : HTTP error code  : "+ conn.getResponseCode());
        throw new RuntimeException("Failed : HTTP error code : "
          + conn.getResponseCode());
     }
     else {
        //get all headers
        Map<String, List<String>> map = conn.getHeaderFields();
        for (Map.Entry<String, List<String>> entry : map.entrySet()) {
         System.out.println("Key : " + entry.getKey() + 
                        " ,Value : " + entry.getValue());
        }

        String  location= conn.getHeaderField("Location");
        System.out.println("************************ location : "+location);

       Object content = (Object) conn.getContent();
       System.out.println("*****************  Url Content type : "+content.getClass().getName());

       InputStreamReader streamReader = new InputStreamReader((InputStream)conn.getContent());

       BufferedReader br = new BufferedReader(streamReader);
       String output;
       System.out.println("****************** Output from Server .... \n");
       while ((output = br.readLine()) != null) {
        System.out.println(output);
       }

       conn.disconnect();
     }

    Also the response I get back using Advanced Rest Client gives me back header Location but using the java code I get null.

    Kindly help me out with the problem.  Thanking in advance.

    Tuesday, July 28, 2015 8:01 AM