OneDrive Developer Center (redirect)

Looking for the Live SDK?

OneDrive logo

The Live SDK 5.6 is now available

Find it on the OneDrive Dev Center, the new place to find samples, documentation, and other resources for integrating OneDrive into your app.
Choose your download

If you're using previous versions of the Live SDK, the Live SDK 5.5 reference is still available.

 locked
Bad Request (Invalid URL)

    General discussion

  • I am trying to get all of my contacts using the following code.

    import org.apache.commons.httpclient.*;

     import org.apache.commons.httpclient.methods.*;

    import org.apache.commons.httpclient.params.HttpMethodParams;
    import org.apache.commons.httpclient.Header;

    import java.io.IOException;

    public class MsnContactAPITest {
        public static void main(String[] args){
           
            String DAT = "EwCoARAnAAAUWkziSC7RbDJKS1VkhugDegv7L0eAALUQZdS8lXcesAHIGd0GoD9mJUrNMbGFZNn%2BlzN6PHwVIOJTyECcySNGcQkOV2oJ6abh7j1ElBVA3iwD5%2FDEBl1gdUnGTSL%2BCFDzGLysHNlQLZOOUbxS2jBNiGi38qy0UHAmYKM%2BmQGtVxcRpejiMgwoDUg7pRvGjSgSfavOlWx8A2YAAAiaan6hguap9%2FgAwd9cMYP3S%2BIVAZv2eQj%2Bpm5E%2Fake7ihbA6NGDeFoboi6Eme8%2FNckWgURlubuHY795irVUuNzJv8L11NqiEFGAPls8%2FDLZ0HOLo36e%2B3OVBvln92ZClF1U3VBL3ubBjtGtTx1qop32A1C3m7pWXAU8hG6aQY0Bf5Uuipv%2BO20NCU8QalBWFJVUaWvmTjygNJH7gowIYWwjFlZFSdB5DNXLmwW4wiWCHMAf3kTVTfIIyE5UWbuEHPSs25zQDqX83D6ZvswFIBYp2utcmXPphATEnCZcWrY15bC7r9jnVxNP%2FJQH9FPu40CBvnjZjCfSuQxuGDNE3QP0FEAAA%3D%3D";
            String lid = "eact%3DxOaU51q58pqqZAMpww48gU9ffzexdYVitPoQz2ST0FASNNoWGOcIN1ZkbrVkKVEgHp%252FjHqHddldA9rpphthDqrwzzA150qPU4n%252FPSwnJLnbktGkH1%252FzsXqg8Pv3m9YXzboCUam3Xm8b%252BLuDkVu%252BLn1otEDtVuRjMyzVN9m9epoObadUo%252FGdlKF6vS%252B4Wx0%252FlNP3rr1Ynh5j%252B64mwRxPlpTc96HF7LNdDdwFveONUn%252FMB%252BndPNoLFD3bRlMloJOhZMRUsZUUniUJfcaV317hp5zx5zBnazv4uVwMiuug4fS%252B6XxYCHGdrKHR8NEswy5KXODvgFZUaiQCQHrwG3KfSKNDJ5aHeFRaVBiDtjdTvFW%252BN3wtCCAE9phLf7tLqJ31%252F8a1Y9nmzi3WGvUmam2NefSta9R0i%252B7N57wXNqtToxCRJWvLeR%252BFDyfR0BCFHrUUnpSwahv3ju4PNmWCW4HwA4hqDQS6jjK6g5un%252FiRohavcXu9Fg%252FuxV1WL4rHuRt2cJs75o3vB5qUKew3sI%252BUXwNjw3wQYxKLezEYwHBepHSKSdkbweMt2JFAznJCu8P9wctUl5N4kqqkNuu7O1pG9SSXoxZaSvq53uRnxLoxDz0zYqGblytxGcVvwfiEpXRrxFT9L8aeMdU0BK8cnQsymmrHjhvBk2biKt5GBqcyORfS3FKKD%252FJE%252FI1H8Yw0AoIl3C44%252FFbQCBEi%252BiITr2edb%252BN9M5piI0R0zPYKzXyVjO0uu5kdZRNw%252FmjseHU1CpnkzEZphdgC3B5BkDcn9K7XNMRfaNp9o7V4fAPmk1Chfshmoct2y1Fyvhh7rKO%252FTLnv7RONfaaRvCeWCnAr0wyHSTvI55zrETPRJhp3iqXVeoTMwUC9Sv%252BrDb8UP%252B59cUQan7XN%252BnCSYQLuKsexudoypre9QyP8TRoTum1X5Of9eFu2PA2W8%252B6iSJcetAFGtTlAVBZ8vl4ci9gRU%252BDhClqiecYo4Yy0b5BSUVQi0qLaU7Nqsgcj%252BoMVV8zL3xBY5%252FijLZWRDe5NfRb%252BM4RD41uy8agOjZNBrtzaI0GxVJjywb80QNeBZ1dZvhB6kw1IZCfUxjUglddtzUw7zV8ELXkaUxBPV2WHVPKC4nzR7JSayGWAx7poB5rjMKJpXLNGUrgmPw9%252BP7IzVIsRDXele6cSphUUBRgXpOuyKT5TxOz5RultBiu4c1dcLjDvtg664hK%252Fhkg95Z%252F1C9F7AZo32kcyDe5c%252FhCIYFVoDbl3idSrqGMqqzaZfgr9p0Mt%252BzXzpIP1cw";
           
           
            String uri ="https://livecontacts.services.live.com/users/@L@"+lid+"/rest/livecontacts/contacts";
           
            HttpClient client = new HttpClient();
            HttpMethod method = new GetMethod(uri);
            Header header = new Header("Authorization", "DelegatedToken dt=\"" + DAT + "\"");
            Header contentType = new Header("Content-Type", "application/xml; charset=utf-8");
            method.addRequestHeader(header);
            method.addRequestHeader(contentType);
           
            //method.setRequestHeader("Authorization", "DelegatedToken dt=\"" + DAT + "\"");
            // Provide custom retry handler is necessary
            method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                    new DefaultHttpMethodRetryHandler(3, false));
            try{
               
                int statusCode = client.executeMethod(method);
               
                if (statusCode != HttpStatus.SC_OK) {
                    System.err.println("Method failed: " + method.getStatusLine());
                }
                byte[] responseBody = method.getResponseBody();
                System.out.println("==================The response body is=====");
                System.out.println(new String(responseBody));
                System.out.println("==================End of response body=====");
           
            }catch (HttpException e) {
                //System.err.println("Fatal protocol violation: " + e.getMessage());
                System.out.println("Fatal protocol violation: " + e.getMessage());
                e.printStackTrace();
            }catch (IOException e) {
                System.err.println("Fatal transport error: " + e.getMessage());
                e.printStackTrace();
            }finally {
                // Release the connection.
                method.releaseConnection();
             
            }

        
           
        }

    }

     The output of the above program is:

    Method failed: HTTP/1.1 400 Bad Request

     ==================The response body is=====
    <h1>Bad Request (Invalid URL)</h1>
    ==================End of response body=====

     Can some one please help me out that why i can not get the contacts back and why i get the above response? I get the DAT and LID as displayed by the Sample1 of the delegated Authentication guide.

    I will highly appreciate any response in this regard. 

     

     Best Regards,

    Faisal

     

     

     

    Wednesday, January 28, 2009 8:52 AM

All replies

  • Your lid is wrong. The lid (Location ID) is a string of numbers, which is the Unique User ID. It's passed on as the CID, a 16 character long hexadecimal (base 16) string, which you should convert to decimals (base 10) yourself. Then you get the right URI.
    Wednesday, January 28, 2009 9:36 PM
OneDrive Developer Center (redirect)

Looking for the Live SDK?

OneDrive logo

The Live SDK 5.6 is now available

Find it on the OneDrive Dev Center, the new place to find samples, documentation, and other resources for integrating OneDrive into your app.
Choose your download

If you're using previous versions of the Live SDK, the Live SDK 5.5 reference is still available.