Filtre by date google search api

47 views
Skip to first unread message

Mark videochoc

unread,
Sep 21, 2014, 6:04:09 PM9/21/14
to google-a...@googlegroups.com

i used google search api to develop my application is there any way to add a filter by date, i checked out the documentation and i found nothing also i tired the parameter qdr:m as shown in google web url but it didn't work...NB im using google search api PHP this is my code

function curl_get($url, $params) { $post_params = array(); foreach ($params as $key => &$val) { if (is_array($val)) $val = implode(',', $val); $post_params[] = $key.'='.urlencode($val); } $post_string = implode('&', $post_params);

$fullurl = $url."?".$post_string;

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_URL, $fullurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mailana (curl)');
$result = curl_exec($ch);
curl_close($ch);

return $result; }
function perform_google_web_search($termstring,$siteweb = null,$qrd = null) {
$start = 1;
$result = array();
while ($start<50)
{
    $searchurl = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0';
    $searchurl .= '&key=';
    $searchurl .= '&start='.$start;
    $searchurl .= '&rsz=large';
    $searchurl .= '&filter=0';
    $searchurl .= '&q='.urlencode($termstring).$siteweb;
    $searchurl .= '&tbs='.$qrd;

    $response = curl_get($searchurl, array());

    $responseobject = json_decode($response, true);

    if (count($responseobject['responseData']['results'])==0)
        break;

    $allresponseresults = $responseobject['responseData']['results'];

    foreach ($allresponseresults as $responseresult)
    {
        $result[] = array(
            'url' => $responseresult['url'],
            'title' => $responseresult['title'],
            'abstract' => $responseresult['content'],
        );

    }

    $start += 8;
}

return $result; }

Vinny P

unread,
Sep 23, 2014, 12:07:21 AM9/23/14
to google-a...@googlegroups.com
On Sun, Sep 21, 2014 at 5:04 PM, Mark videochoc <info....@gmail.com> wrote:

i used google search api to develop my application is there any way to add a filter by date, i checked out the documentation and i found nothing also i tired the parameter qdr:m as shown in google web url but it didn't work...NB im using google search api PHP



The first issue is that you appear to be using the Web Search API, which was deprecated years ago and is currently scheduled to be shut down soon (read the notes sections on the top): https://developers.google.com/web-search/docs/ . You'll need to migrate to using the Custom Search API: https://developers.google.com/custom-search/docs/tutorial/introduction

For filtering by dates, you can use the dateRestrict property listed here: https://developers.google.com/custom-search/json-api/v1/reference/cse/list#request
 
 
-----------------
-Vinny P
Technology & Media Consultant
Chicago, IL

App Engine Code Samples: http://www.learntogoogleit.com

Reply all
Reply to author
Forward
0 new messages