Set Google Calendar request parameters using google-java-api-client in Android

I am creating a url to access the google calendar of users using google-javi-api as such:

CalendarUrl url = CalendarUrl.forEventFeed("accountName", "private", "full"); 

which returns me this url:

 "https://www.google.com/calendar/feeds/ user@gmail.com /private/full?prettyprint=true" 

I would like to set the parameters for this URL with the parameters startMin and startMax, so that in the end the URL looks like this:

 "https://www.google.com/calendar/feeds/default/private/full?start-min=2011-06-00T00:00:00&start-max=2011-06-24T23:59:59" 

All my attempts at this failed, and after registering the return URL, I found that "?" is replaced by "% 3F", and ampersands are replaced by "&"

Invalid url returned:

 "https://www.google.com/calendar/feeds/default/private/full%3Fstart-min=2011-06-00T00:00:00&start-max=2011-06-24T23:59:59" 

I am sure the reason my result set is null is the replacement of these characters. How to add source URL with new parameters?

** If you are interested in how I build this URL, I use the CalendarURL class from this Google implementation example of Google Calendar .

EDIT

In particular, in the CalendarURL class, I can add parts to the "path" of the URL, but I cannot find a way to include the query parameter. Does this API not include a way to specify a parameter?

+2
source share
2 answers

The correct way to create a URL using google-java-client-api is to extend the GoogleUrl object. (I use Google Latitude here as an example. I create a GoogleUrl object, and later you will see how it will be used).

Google URL Object

  • You create a URL object that extends GoogleUrl
  • You are commenting on the parameters you want to configure on the URL using the @Key annotation
  • You provide a constructor that accepts a root URL.
  • You add details to the context using the pathParts.add method

An example URL object is as follows:

 public final class LatitudeUrl extends GoogleUrl { @Key public String granularity; @Key("min-time") public String minTime; @Key("max-time") public String maxTime; @Key("max-results") public String maxResults; /** Constructs a new Latitude URL from the given encoded URI. */ public LatitudeUrl(String encodedUrl) { super(encodedUrl); } private static LatitudeUrl root() { return new LatitudeUrl("https://www.googleapis.com/latitude/v1"); } public static LatitudeUrl forCurrentLocation() { LatitudeUrl result = root(); result.pathParts.add("currentLocation"); return result; } public static LatitudeUrl forLocation() { LatitudeUrl result = root(); result.pathParts.add("location"); return result; } public static LatitudeUrl forLocation(Long timestampMs) { LatitudeUrl result = forLocation(); result.pathParts.add(timestampMs.toString()); return result; } } 

Using

This object is used to create a URL, just fill in your parameters (annotated @Key fields) and execute the build () method to get its string representation:

  LatitudeUrl latitudeUrl = LatitudeUrl.forLocation(); latitudeUrl.maxResults="20"; latitudeUrl.minTime="123"; latitudeUrl.minTime="456"; System.out.println(latitudeUrl.build()); 

Exit:

 https://www.googleapis.com/latitude/v1/location?max-results=20&min-time=456 
+4
source

After some serious digging, I learned how to enable query parameters using google-java-api.

To add any of these Request Parameters to the URL, do the following:

After creating the base CalendarUrl, call .put ("Key", "Value") to add query parameters. For instance:

 CalendarUrl eventFeedUrl = CalendarUrl.forEventFeed(" user@gmail.com ", "private", "full"); eventFeedUrl.put("start-min", "2011-06-01T00:00:00"); eventFeedUrl.put("start-max", "2011-06-22T00:00:00"); 

I just accidentally stumbled upon a thread buried among an unwanted download of unfiltered โ€œproblemsโ€ in a project home on Google. There is a lot of documentation for using gData api, but for google-java-api there is NOTHING. It took me almost 2 days to find this simple method. Very frustrating. I hope that the one who reads this does not go through what I went through to figure out how to accomplish this simple but decisive task. This should be better documented.

+1
source

All Articles