0

My Goal is to request GoogleTaskAPI for TASKLIST with specified no.of result. It works fine, If I m passing no requestBody. But I need to pass request parameter to specific number of results to be returned. When I do that, it creates new Tasklist, Instead of listing. So how to do this?

My Code:

    GoogleAccessProtectedResource access = new GoogleAccessProtectedResource(accessToken, httpTransport, jsonFactory, clientId, clientSecret, refreshToken);
    HttpRequestFactory rf = httpTransport.createRequestFactory(access);

    String endPointUrl = "https://www.googleapis.com/tasks/v1/users/@me/lists";
    String requestBody = "{\"maxResults\":3}";

    GenericUrl endPoint = new GenericUrl(endPointUrl);
    ByteArrayContent content = new ByteArrayContent("application/json", requestBody.getBytes());

    //Try 0: Works, But Retrieving all of my Tasklist, I need only 3
    //HttpRequest request = rf.buildGetRequest(endPoint);
    //-------

    //Try 1: Fails to retrieve
    //HttpRequest request = rf.buildGetRequest(endPoint);
    //request.setContent(content);
    //request.getContent().writeTo(System.out);
    //-------

    //Try 2: Fails to retrieve
    HttpRequest request = rf.buildRequest(HttpMethod.GET, endPoint, content);
    request.getContent().writeTo(System.out);
    //-------

    HttpResponse response = request.execute();
    String str = response.parseAsString();
    utils.log(str);  
Kaymatrix
  • 615
  • 2
  • 8
  • 16

1 Answers1

1

maxResults is a query parameter, not a request parameter, so you can just put it in the url:

String endPointUrl = "https://www.googleapis.com/tasks/v1/users/@me/lists?maxResults=3";

You should also consider using the Java client's Tasks interface for making requests; it may be a little easier since it handles the details of the url for you:

http://code.google.com/p/google-api-java-client/wiki/APIs#Tasks_API

monsur
  • 45,581
  • 16
  • 101
  • 95
  • gr8, it works awesome. But I wonder why previously it was creating new empty _tasklist_ instead of throwing error response or default _tasklist_ – Kaymatrix Sep 19 '12 at 03:09