将Google Sheets单元格的内容加载到php变量中


Loading contents of a Google Sheets cell into a php variable

我试图加载谷歌表的单个单元格的内容到一个PHP变量。从那里,我打算使一个网站上的图像更改时,单元格内容更改为不同的值。我不能让单元格的内容加载到一个PHP变量来让这个球滚动。

Google Sheets API提供了以下PHP代码来完成此操作:

$result = $service->spreadsheets_values->get($spreadsheetId, $range);

当我在替换我的电子表格和范围后使用这段代码时,我回显$result并没有得到任何东西。我确信代码中遗漏了一些东西,或者需要定义变量$result或$service,但是Google显然在PHP方面犯了错误。

从:https://github.com/google/google-api-php-client-services/issues?utf8=%E2%9C%93& q = spreadsheets_values

在服务器上复制

,验证所需

的路径

把你的代码在一个例子中,与类声明为$service和变量$range, $ spreadsheid和$api_key(从谷歌的浏览器api)来验证:https://console.developers.google.com/apis/credentials)

运行修改后的示例

PS:我寻找多范围,以防您找到方法:

$range[]= 'Sheet1!A:C'; // I try to have all sheets in once
$response = $service->spreadsheets_values->get($spreadsheetId, $range);
$values = $response->getValues();