Home  >  Article  >  Backend Development  >  How to access Google Search API with PHP_PHP Tutorial

How to access Google Search API with PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:04:481072browse

How to access Google Search API with PHP

This article mainly introduces the method of accessing Google Search API with PHP. It analyzes the skills of PHP for accessing Google API with examples, which has certain reference. For reference value, friends in need can refer to it

The example in this article describes how to access Google Search API with PHP. 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:

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/963987.htmlTechArticleHow to access Google Search API with PHP. This article mainly introduces the method of accessing Google Search API with PHP and analyzes it with examples. PHP's skills for Google API access have certain reference value and need to be...
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