7

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.

Michał Ziober
  • 37,175
  • 18
  • 99
  • 146
applecrusher
  • 5,508
  • 5
  • 39
  • 89

3 Answers3

15

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:

Michał Ziober
  • 37,175
  • 18
  • 99
  • 146
  • I have tried this as well. Here is my URL that I have. http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=bank+fraud+new+york&dateRestrict=d1. However here is the second result I am getting: http://boss.blogs.nytimes.com/2012/12/12/a-win-for-small-businesses-in-bank-fraud-case/ Kabul – applecrusher Jan 27 '13 at 02:08
  • On the https://developers.google.com/custom-search/v1/using_rest page, Google recommends to use this URI: https://www.googleapis.com/customsearch/v1?parameters. I don't know where were you find ajax.googleapis.com URI but it probably is not correct. – Michał Ziober Jan 27 '13 at 17:32
1

I was trying the same thing, and dateRestrict for an absolute time range didn't seem to work. The pages that were not in the date range also appeared. The workaround I found is to use the sort feature. The query will look something like this:

(q='search_term' , cx='search_engine_id', sort = 'date:r:yyyymmdd:yyyymmdd')

The sort feature allows us to sort and filter the date of the results to the time range specified.

Mohd Maaz
  • 267
  • 5
  • 20
0

I know question asked for this awhile ago, I had the same problem.

Use dateRestrict=d1 instead of dateRestrict=d[1]

The documentation made that a bit confusing. [] is used to show number as placeholder.

Taksh
  • 68
  • 4