Datadimension
Datadimension

Reputation: 1045

Google Calendar API PHP

I am trying to search Google Calendar by created (item field). This fails to give any results.

$optParams = array(
    'maxResults' => 10,
    'orderBy' => 'startTime',
    'singleEvents' => true,
    "q"=>"created>2020-06-14T16:09:16.000Z"
    );
$results = $this->service->events->listEvents("primary", $optParams);
$events = $results->getItems();

I have also tried to test this 'q' search with timeMin

$optParams = array(
    'maxResults' => 10,
    'orderBy' => 'startTime',
    'singleEvents' => true,
    "q"=>"timeMin>2020-06-14T16:09:16.000Z"
    );
$results = $this->service->events->listEvents("primary", $optParams);
$events = $results->getItems();

and the same issue with no results.

Events, calendar access and $this->service are proven with much the same code, but using timeMin as optional parameter instead of 'q'

$optParams = array(
    'maxResults' => 10,
    'orderBy' => 'startTime',
    'singleEvents' => true,
    "timeMin"=>"2020-06-14T16:09:16.000Z" // *** note this is instead of 'Q' ***
    );
$results = $this->service->events->listEvents("primary", $optParams);
$events = $results->getItems();

My question is what is actually permissable when searching using 'q' and how should it be constructed. As expected the Google documentation is very vague.

Upvotes: 0

Views: 104

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116868

If you check the documentation for event.list you will see that

q string Free text search terms to find events that match these terms in any field, except for extended properties. Optional.

Its a free text search string. This means that you can search on the name of an even or a description.

The following would return any even that had a title or a description of birthday.

$optParams = array(
    'maxResults' => 10,
    'orderBy' => 'startTime',
    'singleEvents' => true,
    "q"=>"Birthday"
    );
$results = $this->service->events->listEvents("primary", $optParams);
$events = $results->getItems();

That it is a free text search on any field i tried to do a search on a date from one of my events and that sadly did not work.

$optParams = array(
    'maxResults' => 10,
    'orderBy' => 'startTime',
    'singleEvents' => true,
    "q"=>"2008-09-22T13:43:40.000Z"
    );
$results = $this->service->events->listEvents("primary", $optParams);
$events = $results->getItems();

What you should be doing is something more along the lines of

$optParams = array(
    'maxResults' => 10,
    'orderBy' => 'startTime',
    'singleEvents' => true,
    "mintime"=>"2012-03-19T08:42:11.000Z",
    "maxtime"=>"2012-03-19T10:42:11.000Z"
    );
$results = $this->service->events->listEvents("primary", $optParams);
$events = $results->getItems();

which will return the events based upon your time. Unfortunately this is not the created time it searches on but rather the event time.

Upvotes: 2

Related Questions