According to the description of the Google Custom Search API, you can call it using the GET verb of the REST interface, for example, using an example:
GET https:
I configure my API key and user search system, and when I inserted my test request directly into my browser, it worked fine, and I received a JSON file for me.
Then I tried to call the API from my PHP code using:
$json = file_get_contents("$url") or die("failed");
Where $ url was the same that worked in the browser, but my PHP code was dying when trying to open it.
After that I tried with curl and it worked. The code was as follows:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $body = curl_exec($ch);
Questions
- How come the get_contents () file did not work and curl did?
- Can I use fsocket for this?
rest php
Daniel Scocco
source share