Search code examples
javagoogle-custom-search

How to use "dateRestrict" parameter in Custom Search API


I am trying to modify some java code which uses the Google API. One of the features I have not been able to get is the dateRestrict. Information about this can be found here: GoogleAPI

To implement this I attach the following string after my query. It is properly connected with the full URL because other parameters work with it.

String parameters = "&dateRestrict=2012-01-01";

I have also tried 1d and 1m but those don't work either as parameters

If someone could show me of an example of dateRestrict I would greatly appreciate it. I just don't understand how they mean to use it in the API. Thank you.


Solution

  • On the Using REST to Invoke the API you can find information about dateRestrict parameter. Notes about parameter: Restricts results to URLs based on date. Supported values include:

    • d[number]: requests results from the specified number of past days.
    • w[number]: requests results from the specified number of past weeks.
    • m[number]: requests results from the specified number of past months.
    • y[number]: requests results from the specified number of past years.

    Example usage should look like this:

    String parameters = "&dateRestrict=d20";
    

    or

    String parameters = "&dateRestrict=y1";
    

    I think, you can play with APIs Explorer for this method for better understanding this parameter.

    Also see: