Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Custom Search API curl trouble

Tags:

search

api

I'm a newbie at stackoverflow so please be patient with me :)

I'm trying to get access with the Google Custom Search API. But I get return that I can't understand.

My query is like this:

https://www.googleapis.com/customsearch/v1?&key=********&q=red%2Bsox&cx=**********&start=0&num=10&cr=countryCA&lr=lang_fr&client=google-csbe&output=xml_no_dtd

And the result I get is this?

string '{"error": {"errors": [{"domain": "global","reason": "invalid","message": "Invalid Value"}],"code": 400,"message": "Invalid Value"}}' (length=172)

What am I doing wrong? I want the result from Google to appear.

Thanks in advance :)

like image 374
Claes Avatar asked Jan 24 '13 18:01

Claes


1 Answers

You don't have a cx. Take a look at this answer What happens is because this api is used mostly for adding a search option for your site you have to specify you custom search engine (e.g. search only your site). When you want this to search the web by code you need to do the above. Add a fake site (where you would add your search textbox), configure it (search the web, or your site, or whatever else) and then delete the fake site

Update

Oh god, i just saw that. Sorry. Well the problem is that you start with 0. Valid is 1. Change start=0 with start=1 and i think you would be good to go. Take a look at this for valid values for the start parameter official page

like image 118
Alkis Kalogeris Avatar answered Nov 14 '22 10:11

Alkis Kalogeris