【问题标题】:Google Image Search returns no resultsGoogle 图片搜索未返回任何结果
【发布时间】:2017-01-19 10:19:51
【问题描述】:
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。我在这里做错了什么?

【问题讨论】:

    标签: php search google-api google-search


    【解决方案1】:

    原来为 API 设置的 referrer 不正确。我暂时关闭了它,它起作用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-02
      • 1970-01-01
      相关资源
      最近更新 更多