“permissions"不足;当试图获得谷歌电子表格元信息


"insufficient permissions" when trying to get Google Spreadsheet meta info

我很快就需要将数据逐行添加到现有的~1000条记录电子表格中。我想通过制作一个小的PHP页面来简化我的工作,该页面将显示一行数据,并为我提供一个表单,以便将我想要的数据添加到该行。电子表格是在驱动器,使我到驱动器API!:)

我已经下载了Google API客户端管理器,并开始使用OAuth 2.0示例(缩短URL)。这一切都很好,但现在我正试图从电子表格中获取一些我需要的元数据。无论我对驱动器使用哪种类型的调用,我总是得到以下错误:

致命错误:未捕获的异常'Google_Service_Exception'伴有消息'错误调用POST https://www.googleapis.com/drive/v2/files:(403)权限不足'

你知道是什么原因导致的吗?作为参考,下面是我的代码:

<?php
session_start();
set_include_path("google-api-php-client-master/src/" . PATH_SEPARATOR . get_include_path());
require_once 'Google/Client.php';
require_once 'Google/Service/Drive.php';
$client_id = 'xxx';
$client_secret = 'xxx';
$redirect_uri = 'http://localhost/coding/';
//SETTING UP THE CLIENT
$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope('https://www.googleapis.com/auth/drive');
$client->addScope('https://spreadsheets.google.com/feeds');
$service = new Google_Service_Drive($client);
//QUICK LOGOUT MECHANISM
if (isset($_REQUEST['logout'])) {
  unset($_SESSION['access_token']);
}
//HANDLE OAUTH
if (isset($_GET['code'])) {
  $client->authenticate($_GET['code']);
  $_SESSION['access_token'] = $client->getAccessToken();
  $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
  header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
  $client->setAccessToken($_SESSION['access_token']);
} else {
  $authUrl = $client->createAuthUrl();
}
//TALK TO DRIVE
if ($client->getAccessToken()) {
    //THIS GOES WRONG :)
    $service->files->get('xxx');
}
if (isset($authUrl)): ?>
  <a class='login' href='<?php echo $authUrl; ?>'>Connect Me!</a>
<?php else: ?>
  <a class='logout' href='?logout'>Logout</a>
<?php endif ?>

在开发者控制台上只启用了Drive API,而不是SDK。谢谢!