我需要创建一个网页来显示 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]);
}
}
?>
关于php - 有什么方法可以从共享的 Google Sheet 文档中获取数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41381591/