P_S
P_S

Reputation: 345

Search does not match single characters in Google Calendar API queries?

In my Google Calendar, I have an event called "What's that? Nothing." If I run the following query, the event is properly found:

eventsResult = service.events().list(
    calendarId=CALENDAR_ID,
    q="Nothing.").execute()

However, if I try to look for the full title, including the single quotation mark, it is not found:

eventsResult = service.events().list(
    calendarId=CALENDAR_ID,
    q="What's that? Nothing.").execute()

I am pretty sure this is not an issue of having the wrong character in the string, since I tried copying the whole title from the calendar itself and from the results of the first (working) request, to no avail. Is there any escaping or encoding I should do?

UPDATE:

The problem is not limited to single quotes. An event called "aa.bb.cc" is found without problems, as is "aa.b.cc". However, "a.b.cc" is not found. The same is true without dots; "aa b cc" is found, but not "a b cc". It seems to be some kind of issue with single-characters, but I do not know yet when exactly it occurs...

Upvotes: 1

Views: 397

Answers (2)

Oleg Gopkolov
Oleg Gopkolov

Reputation: 1684

str = "\"What's that? Nothing\".\""
eventsResult = service.events().list(calendarId='primary', q=str).execute()        

events = eventsResult.get('items', [])

if not events:
    print('No upcoming events found.')
for event in events:
    start = event['start'].get('dateTime', event['start'].get('date'))
    print(start, event['summary'])

Please , see "str". This is what you want. Output of this

Finding the calendar events
2015-09-16T13:30:00+03:00 "What's that? Nothing."

Upvotes: 4

Gerardo
Gerardo

Reputation: 3845

Try sending the quotations as part of the string like:

eventsResult = service.events().list(
    calendarId=CALENDAR_ID,
    q='"Nothing."').execute()

The query usually searches for the terms separated by spaces q=term1 term2 term3 as described here.

When it looks for q=aa b cc the first term is 'aa'. The search is probably easier because the parameter 'aa' won't probably have much repetitions. But having it to search q=a b cc, makes it a little bit ambiguous to find all the elements that contains a and b.

In the documentation i shared, is also mention that to make exact search queries you have to use quotations: q="a b cc". In this way the whole string is treated as one term.

I tried this way in the api explorer and was able to find that event. Without the quotations marks (as you mentioned), the api couldn't find it.

Upvotes: 1

Related Questions