farbod
farbod

Reputation: 11

how can I enter a date restriction when using the Google Search API?

I'm wanting to use the Google Search API and find results based on the fact that they are only a day old. I can do this through the Google search engine but I can't seem to find a way to do this by using the API.

my code: $googleFullURL = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=large&start=$searchIndex&lr=lang_en&filter=0&q=$searchTerms";

I tried using "&tbs=,qdr:d" at the end of my search which is what the search engine appends at the end of the URL when restricting to a date range but this seems to not be working.

thanks

Upvotes: 1

Views: 1972

Answers (1)

kiwixz
kiwixz

Reputation: 1398

You want to use the dateRestrict parameter which is a string.

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.

Documentation for parameters: https://developers.google.com/custom-search/json-api/v1/reference/cse/list

Upvotes: 1

Related Questions