Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify multiple values on siteSearch in google custom search api?

I'm using the google custom search api and want to create a search using the siteSearch:

https://www.googleapis.com/customsearch/v1?key=k&cx=cx&q=cocos2d&siteSearch=www.cocos2d-iphone.org&siteSearchFilter=i

and it works fine (returns all the result only from the given site).

Then I want to specify TWO sites to search so I tried to change the :
siteSearch=www.cocos2d-iphone.org

to 
siteSearch=www.cocos2d-iphone.org www.XXXXXXXX.org
siteSearch=www.cocos2d-iphone.org|www.XXXXXXXX.org
siteSearch=www.cocos2d-iphone.org||www.XXXXXXXX.org

but none of these works.

hope someone can help here, thanks:)
like image 749
supersuraccoon Avatar asked Apr 22 '13 06:04

supersuraccoon


People also ask

How do I get more than 10 results on Google API?

IF YOU ARE USING THE API Google Custom Search and Google Site Search return up to 10 results per query. If you want to display more than 10 results to the user, you can issue multiple requests (using the start=0, start=11 … parameters) and display the results on a single page.

How do I use Google Custom Search API?

Custom Search JSON API requires the use of an API key. An API key is a way to identify your client to Google. After you have an API key, your application can append the query parameter key=yourAPIKey to all request URLs. The API key is safe for embedding in URLs, it doesn't need any encoding.

How do I get a Google Custom Search API key?

You can get an API key by visiting https://code.google.com/apis/console and clicking "API Access". You will then need to switch on the custom search API on the "Services" tab.


Video Answer


2 Answers

Currently I don't believe you can specify more site through the query param siteSearch.

nevertheless you can configure your Custom Search Engine here: https://www.google.com/cse/manage/all in the "Site to search" area.

This also works for excluding, as you can read here: https://support.google.com/customsearch/bin/answer.py?hl=en&answer=2631038&topic=2601037&ctx=topic

like image 61
simotrone Avatar answered Oct 03 '22 20:10

simotrone


You cannot do this with the as_sitesearch parameter as that only accepts a single value. But you can achieve what you want with the as_q parameter, setting it to some value like: "site:google.com OR site:microsoft.com" - that will work in a similar way to this search.

The as_q parameter is documented here as:

The as_q parameter provides search terms to check for in a document. This parameter is also commonly used to allow users to specify additional terms to search for within a set of search results. Examples q=president&as_q=John+Adams

like image 26
netgenius.co.uk Avatar answered Oct 03 '22 19:10

netgenius.co.uk