gpt4 book ai didi

php - 有什么方法可以从共享的 Google Sheet 文档中获取数据吗?

转载 作者:行者123 更新时间:2023-12-02 08:30:21 25 4
gpt4 key购买 nike

我需要创建一个网页来显示 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

关于php - 有什么方法可以从共享的 Google Sheet 文档中获取数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41381591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com