我刚刚开始使用 Google API for Custom Search Engine,并且成功地完成了我的第一个请求,如下所示:
My_first_Search.php
require_once 'apis/apiClient.php';
require_once 'apis/contrib/apiCustomsearchService.php';
session_start();
$client = new apiClient();
$client->setApplicationName('Google CustomSearch PHP Starter Application');
// Docs: http://code.google.com/apis/customsearch/v1/using_rest.html
// My developer key (simple api key).
$client->setDeveloperKey('***********************************');
$search = new apiCustomsearchService($client);
// executing a search with your custom search id.
$result = $search->cse->listCse('burrito', array(
'cx' => '123456789123546789:*******', // The custom search engine ID to scope this search query.
));
print "<pre>" . print_r($result, true) . "</pre>";
// executing a search with the URL of a linked custom search engine.
$result = $search->cse->listCse('burrito', array(
'cref' => 'http://www.google.com/cse/samples/vegetarian.xml',
));
print "<pre>" . print_r($result, true) . "</pre>";
输出: 此文件burrito
以 JSON 格式正确输出关键字的结果
如何淡化然后使用 for-each 循环操纵结果以获得:
- Result title
- Result description
- URL
任何帮助将不胜感激。