Google Api Php客户端-电子表格权限错误

阿伦·库马尔

我正在使用Google PHP客户端访问电子表格数据。

我收到此致命错误:

致命错误:带有消息“ {{错误”:{“代码”:403,“消息”:“呼叫者没有权限”,“错误”:[{“消息”:“呼叫者有没有权限”,“域”:“全局”,“原因”:“禁止”},“状态”:“ PERMISSION_DENIED”}}

我的代码:

  $client = new Google_Client();
  $client->setApplicationName("Google spreadsheets");
  $client->setDeveloperKey("xxxxx");
  $client->setScopes(array('https://www.googleapis.com/auth/drive',    
  'https://www.googleapis.com/auth/spreadsheets.readonly',     
  'https://www.googleapis.com/auth/drive.file'));

  $service = new Google_Service_Sheets($client);

  $range = 'Class Data!A2:E';
  $response = $service->spreadsheets_values->get($sheetid, $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\n", $row[0], $row[4]);
    }
  }

如何解决这个问题?

戴姆敦

像获取其他用户一样,获取服务帐户的电子邮件地址并与其共享工作表。然后它将可以访问工作表

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

下载 Google 电子表格 Google API PHP

使用客户端API在Google云端硬盘应用数据文件夹中创建Google表格电子表格

使用 PHP API 在 Google Drive 电子表格中对表格进行排序

如何在 google 电子表格中为 google api 项目打开访问权限?

表单中是否存在检查表Google电子表格API PHP

如何使用 php google api 更改电子表格的列宽

从Google电子表格PHP API的多个工作表中获取行

Google电子表格API,400错误的错误请求:无法解析范围

使用Google Sheets API公开电子表格?

使用 google 电子表格 api 转义文本

从 Google 电子表格请求 BigQuery API 会产生错误

类型错误:无法读取未定义的 Google 电子表格 API 的属性“0”

如何通过 PHP 中的 Google Spreadsheet API 创建带有 json 字符串的电子表格

带有PHP的Google电子表格API v4-如何将空行插入开头

Google API PHP客户端授权

如何通过表格API v4更新Google电子表格

使用Google API向Google电子表格“写入”时出错

在Java的Google驱动器中使用Google Spreadsheet API创建电子表格

使用Google云端硬盘中的Google Spreadsheets API创建电子表格

无法使用python通过Google Drive API下载Google电子表格

如何通过Python中的Google Drive API重命名Google电子表格?

使用Google Sheets API V4 API密钥创建电子表格

如何使用Google Sheets API v4通过PHP在电子表格中创建新工作表或标签

Google Sheets API:创建电子表格或将电子表格移动到文件夹中

使用Python使用Google API将电子表格复制到另一个电子表格

Google PHP Api客户端-我不断收到错误401:未经授权

Google Directory API PHP客户端SDK出现{“ error”:“ invalid_grant”}错误

Google Directory API(PHP客户端)-错误401登录要求

使用 Java 和 Google Drive API 创建一个空电子表格