Home  >  Article  >  Backend Development  >  How to access Google Search API with PHP, googleapi_PHP tutorial

How to access Google Search API with PHP, googleapi_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:05:17900browse

How PHP accesses Google Search API, googleapi

The example in this article describes how PHP accesses Google Search API. Share it with everyone for your reference. The details are as follows:

This code snippet demonstrates how to send a request to the AJAX search API from php. Note that this example assumes PHP 5.2. For earlier installations of PHP, please refer to the corresponding official notes.

The specific code is as follows:
Copy code The code is as follows: $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Paris%20Hilton";

// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.mysite.com/index.html");
$body = curl_exec($ch);
curl_close($ch);

// now, process the JSON string
$json = json_decode($body);
// now have some fun with the results...

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963847.htmlTechArticleHow PHP accesses Google Search API, googleapi This article describes how PHP accesses Google Search API. Share it with everyone for your reference. The details are as follows: This code snippet demonstrates how...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn