在PHP中,我试图通过谷歌api访问谷歌电子书但我收到此错误 .

致命错误:未捕获的异常 'Google_Service_Exception' 与消息“错误调用GET https://www.googleapis.com/books/v1/volumes?q=Henry梭罗&滤波器=自由电子书&键= AIzaSyCc5s6WLKl9SrvlsN-8yXO6Cmd4qeAYR08:(403)的权限不足'in /home/stealthbeta/public_html/google-api-php-client-master/src/Google/Http/REST.php:110堆栈追踪:#0 / home / stealthbeta / public_html / google-api-php-client-主/ SRC /谷歌/ HTTP / REST.php(62):Google_Http_REST :: decodeHttpResponse(对象(Google_Http_Request),对象(Google_Client))#1 [内部功能]:Google_Http_REST :: doExecute(对象(Google_Client),对象(Google_Http_Request ))#2 /home/stealthbeta/public_html/google-api-php-client-master/src/Google/Task/Runner.php(174):call_user_func_array(阵列,阵列)#3 /家庭/ stealthbeta /的public_html /谷歌-api-php-client-master / src / Google / Http / REST.php(46):Google_Task_Runner-> run()#4 / home / stealthbeta / public_html / google-api-php-client-master / src / Google /Client.php(593):Google_Http_REST :: e xecute(对象(Google_Client),对象(转到第110行的/home/stealthbeta/public_html/google-api-php-client-master/src/Google/Http/REST.php

这是我的代码:

require_once 'src/Google/autoload.php';
require_once 'src/Google/Client.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("XXXXXX");
$client->setClientId("XXXXXXX");
$client->setClientSecret('XXXXX');
$client->setRedirectUri('XXXXX');
$client->setScopes(array('https://www.googleapis.com/auth/books'));

if (isset($_GET['code'])) {
    $client->authenticate($_GET['code']);
    $_SESSION['token'] = $client->getAccessToken();

    if (isset($_SESSION['token'])) {
        $client->setAccessToken($_SESSION['token']);
     }
}

if ($client->getAccessToken()) {
    $service = new Google_Service_Books($client);
    $optParams = array('filter' => 'free-ebooks');
    $results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);

    foreach ($results as $item) {
        echo $item['volumeInfo']['title'], "
\n"; } $_SESSION['token'] = $client->getAccessToken(); } else { $authUrl = $client->createAuthUrl(); }

如何解决这个问题?