Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php谷歌电子表格API“;请求的身份验证作用域不足”;_Php_Api_Spreadsheet - Fatal编程技术网

php谷歌电子表格API“;请求的身份验证作用域不足”;

php谷歌电子表格API“;请求的身份验证作用域不足”;,php,api,spreadsheet,Php,Api,Spreadsheet,我对Spreadsheed api和“范围”有问题。 使用这些脚本,我想更新工作表上的单元格 我不与作曲家合作,我只是下载了这个软件包。令牌已存在,错误来自以下行: “$response=$service->spreadsheets\u values->get($spreadsheetId,$range);” 您已定义此范围: $client->addScope(Google\u服务\u驱动器::驱动器\u元数据\u只读) 用于访问电子表格值: $response=$service->sprea

我对Spreadsheed api和“范围”有问题。 使用这些脚本,我想更新工作表上的单元格

我不与作曲家合作,我只是下载了这个软件包。令牌已存在,错误来自以下行:

“$response=$service->spreadsheets\u values->get($spreadsheetId,$range);”


您已定义此范围:
$client->addScope(Google\u服务\u驱动器::驱动器\u元数据\u只读)

用于访问电子表格值:
$response=$service->spreadsheets\u values->get($spreadsheetId,$range)

您应该有:
$client->addScope(谷歌服务表单::电子表格\u只读)

$client->addScope(谷歌服务表单::电子表格)

来源:

您必须更新范围,如@random425所述

但在此之后,删除标记.json
这将再次开始验证过程,什么将为您提供新的令牌,以及您已更改为的新范围。

没有人知道吗?
<?php
session_start();
require_once __DIR__.'/vendor/autoload.php';

$client = new Google_Client();
$client->setAuthConfig('oauth-credentials.json');

$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);

if (isset($_SESSION['access_token']) && $_SESSION['access_token']) 
{
      $client->setAccessToken($_SESSION['access_token']);

      echo "<pre>";   
      $service = new Google_Service_Sheets($client);
      $spreadsheetId = 'xxx';
      $range = 'Tabellenblatt1!A2:E';

        $response = $service->spreadsheets_values->get($spreadsheetId, $range);
        $values = $response->getValues();

        if (count($values) == 0) {
          print "No data found.\n";
        } else {
          print "Name, Major:\n";
          foreach ($values as $row) {
            // Print columns A and E, which correspond to indices 0 and 4.
            printf("%s, %s <br>", $row[0], $row[4]);
          }
        }
    } else {
      $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/api/oauth2callback.php';

      header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
    }
?>
Fatal error:  Uncaught exception 'Google_Service_Exception' with message '{
  "error": {
    "code": 403,
    "message": "Request had insufficient authentication scopes.",
    "errors": [
      {
        "message": "Request had insufficient authentication scopes.",
        "domain": "global",
        "reason": "forbidden"
      }
    ],
    "status": "PERMISSION_DENIED"
  }
}