使用谷歌自定义搜索api时显示未配置的访问权限


Access not configured displayed when using google custom search api

以下脚本由google api php客户端提供

<?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>");
}
?>

执行脚本时,即使services选项卡中启用了custom search,也会显示以下错误。

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

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

转到API控制台,首先从那里启用API。

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

注册您的IPv6地址而不是IPv4