有没有办法从共享 Google Sheet 文档中获取数据?

Is there any way to get data from shared Google Sheet document?

我需要创建一个网页,该网页必须显示 Google 表格中的当前价格。有说明书https://developers.google.com/api-client-library/php/auth/web-app#protectauthcode但需要授权

有没有办法在用户每次打开我的 php 页面时导入数据,即使他没有 Google 帐户?或者我需要创建服务器到服务器的通信并每次通过 cron 任务同步到 json 文件或我的数据库?

我成功了,这是我的解决方案:

<?php
$apiKey="yourAPIkey";
include_once 'vendor/autoload.php';
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$client->setDeveloperKey($apiKey);
$service = new Google_Service_Sheets($client);
$spreadsheetId = 'SheetID';
$range = 'A1:B';
$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) {
    printf("<p>%s, %s</p>", $row[0], $row[1]);
  }
}  
?>

Install library

Get Simple API access key