Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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客户端(或者根本不可以!)在Google Sheets api v4中按标题访问电子表格吗?_Php_Google Sheets_Google Sheets Api - Fatal编程技术网

我可以使用PHP客户端(或者根本不可以!)在Google Sheets api v4中按标题访问电子表格吗?

我可以使用PHP客户端(或者根本不可以!)在Google Sheets api v4中按标题访问电子表格吗?,php,google-sheets,google-sheets-api,Php,Google Sheets,Google Sheets Api,我们曾经通过php访问谷歌电子表格:- $spreadsheetService = new SpreadsheetService(); $spreadsheetFeed = $spreadsheetService->getSpreadsheets(); $spreadsheet = $spreadsheetFeed->getByTitle($spreadsheetTitle); 但是,我看不到任何通过V4API执行此操作的示例。此getByTitle功能是否已删除 在我看来,好像是

我们曾经通过php访问谷歌电子表格:-

$spreadsheetService = new SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
$spreadsheet = $spreadsheetFeed->getByTitle($spreadsheetTitle);
但是,我看不到任何通过V4API执行此操作的示例。此getByTitle功能是否已删除

在我看来,好像是这样。然而,我认为作为一种解决方法,可能有一些方法可以为经过身份验证的Google_客户端获取可用的电子表格列表,该列表将列出电子表格id和标题-这将允许我通过以这种方式获取id,以编程方式将现有代码更新到新的api-但我找不到类似的东西要么

是否有人遇到此问题并找到了解决方案


对于遇到此问题的任何其他人来说,这里有一个可行的解决方案(可能在迁移到v4时):-

您会注意到注释掉的mimeType参数设置。不幸的是,尽管我可以在Google控制台中针对“q”参数添加mimeType,但我无法通过php包装器使其工作。如果有人已经解决了如何做到这一点,请让我知道,我将更新此解决方案…

您可以使用,然后使用返回的ID 开

要了解有关
q
参数的更多信息,请阅读


例如,对于按MimeType以及按标题进行过滤,您可以执行
name='yourname'和MimeType='application/vnd.google apps.spreadsheet'

参考:这不好,即$response=$service->spreadsheets\u values->get($spreadsheetId,$range),我希望通过标题而不是电子表格访问,但它是一个谷歌服务表单对象,而不是电子表格服务我不明白你当时为什么引用它?根据这个问题,如果有一种方法可以在更高的级别获取电子表格id,那就好了,但我不太确定为什么您引用了这个需要知道id的示例?谢谢,这确实是一种方法。请看一下我上面的更新-如果您确实知道应该如何为mimeType设置q参数,这将有助于减少要循环的数组集。谢谢,这个文档链接很有用(我也在看),但正如您将看到的,这里没有php示例。我注释掉了我认为应该在上面的解决方案中使用的参数设置行。我可以在控制台中使用mimeType='application/vnd.google apps.spreadsheet'得到一个结果,这只是我遇到问题的q参数的php代码。
....

$this->spreadsheetService = new Google_Service_Sheets($client);
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
$googleDrive = new Google_Service_Drive($client);
$spreadsheetId = "";

$parameters = [];
//$parameters['q'] = urlencode("mimeType = 'application/vnd.google-apps.spreadsheet'");

$googleDriveFiles = $googleDrive->files->listFiles($parameters);
$files = $googleDriveFiles['files'];

foreach($files as $file){
   if ($file['name'] === $spreadsheetTitle){
       $spreadsheetId = $file['id'];
       break;
   }
}

$range = $worksheetTitle;
$worksheet = $this->spreadsheetService->spreadsheets_values->get($spreadsheetId, $range);
...