0

I've been working with Google Custom Search API and faced some inconveniences I hope you can help me with.

Google Custom Search API offers as a parameter in its call the possibility to search by an exact text as well as exclude it from results: exactTerms and excludeTerms. However, the q parameter is mandatory and cannot be ignored, so if I want to search only by an specific text I just can't.

So how can I do a query using JSON API that contains specifically the text I want? Does the q parameter work as the search form in Google?

If I want results including 'foo', should I do this:

service.cse().list(cx=const.SEARCH_ENGINE_KEY, q='"foo"').execute()

or this?:

service.cse().list(cx=const.SEARCH_ENGINE_KEY, q=None, exactTerms='foo').execute()

Thank you in advance for your time.

yeuk0
  • 43
  • 7

1 Answers1

1

Due to the success on the answers (hehe) I'm posting my own conclusions. Please, if you've any facts regarding the original question, please post it.

I've been testing with some calls to Google CSE API and looks like you can pass to q parameter the same query you'd do in Google's main page textfield. So (at least for my needs), you don't need exactTerms and excludeTerms to get what I was trying to achieve.

Anyway, as I said before, if you know how to work with these parameters I'm sure everybody will thank you.

yeuk0
  • 43
  • 7
  • Yes I agree. q="" works for me, if you don't want exactTerms. Just don't pass exactTerms and use q. Sounds like you want the opposite though. – Cole Peterson Jul 22 '21 at 19:27
  • No, I wanted `exactTerms` to work but I guess it was as easy as using double quotes in those terms you really want to be on search results. Anything you want to be more specific with, just use [usual Google search utilities](https://support.google.com/websearch/answer/2466433?hl=en). – yeuk0 Jul 23 '21 at 20:09