开发者

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

开发者 https://www.devze.com 2023-03-01 10:33 出处:网络
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

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 se开发者_C百科arch 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消