使用Google自定义搜索API时未显示配置

时间:2013-06-26 03:51:30

标签: php google-api google-api-php-client

以下脚本由google api php client提供

<?php
require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_CustomsearchService.php';
session_start();

$client = new Google_Client();
$client->setApplicationName('Google CustomSearch PHP Starter Application');
$client->setDeveloperKey('API KEY');
$search = new Google_CustomsearchService($client);

try{
     $result = $search->cse->listCse('burrito', array('cx' => 'SEARCH ENGINE ID'));
     print "<pre>" .print_r($result, true) . "</pre>";
}catch(Exception $e)
{
     echo("<pre>".print_r($e,true)."</pre>");
}
?>

执行脚本时,即使在custom search标签中启用services,也会显示以下错误。

Google_ServiceException Object
(
    [errors:protected] => Array
        (
            [0] => Array
                (
                    [domain] => usageLimits
                    [reason] => accessNotConfigured
                    [message] => Access Not Configured
                )

        )

2 个答案:

答案 0 :(得分:1)

当您尝试访问尚未从API控制台启用的API时,也会发生此错误。

转到API console并首先启用API。

答案 1 :(得分:0)

https://code.google.com/apis/console

注册您的IPv6地址而不是IPv4