I am new to Json, I've applied the way that worked for google image API and i wondering is it the same way to use it to Google CSE?
$url ="https://www.googleapis.com/customsearch/v1?key=WHATEVER&cx=017728263617760474213:e_b2kmmuyco&q=standard%20form";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://localhost/GSearch2.php");
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body);
print_r($json->items);
There is no results nor errors appearing
NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.
Since recursion depth was increased from 128 to 512 in PHP 5.3.0, there's a good chance that's not the issue, so $body
probably does not contain valid JSON. Ensure that the value of $url
points to valid JSON and look into json_last_error()
Did you try checking the HTTTP response body [may be by printing it]?
Some times a Webservice like Google indicate server side errors in the json content itself.
Ex:
You are expecting a json string { "items": "Sample item" }
but the response json string was something like { "error" : "invalid key/id1" }
[Sorry, I am not very good at PHP, but I have worked with Google APIs and CURL]