ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__.'/vendor/autoload.php';
define('GOOGLE_API_KEY', 'MY-KEY');
define('GOOGLE_CX', 'CX-ID');
$client = new Google_Client();
$client->setApplicationName("My Project Name");
$client->setDeveloperKey(GOOGLE_API_KEY);
$search = new Google_Service_Customsearch($client);
$params = array(
'fileType' => 'png',
'imgSize' => 'large',
'searchType' => 'image',
'filter' => 1,
'num' => 10,
'googlehost' => 'google.co.nz',
'cx' => GOOGLE_CX
);
$q = 'lenovo logo transparent';
try {
$results = $search->cse->listCse($q, $params);
echo '<pre>'.print_r($results,1).'</pre>';
} catch (Google_ServiceException $e) {
$error = $e->getMessage();
} catch (Google_Exception $e) {
$error = $e->getMessage();
}
echo 'Done!';
..不会返回结果,也不会返回任何错误,只会回显Done
。我在这里做错了什么?
答案 0 :(得分:0)
原来,API的referrer
集合不正确。我暂时把它关了,它起作用了。