将值上传到Google表格 [英] Upload values to google sheets
本文介绍了将值上传到Google表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过表格API将数据上传到Google表格,但是我无法找出正确的数据格式.这就是我从文档,
I am trying to upload data to google sheets via sheets API, but I cannot figure out right format of data. This is how I understood It from docs,
public function insert($spreadSheetId)
{
$body = array(
array('ab', 'cd'),
array('ef', 'gh')
);
$values = new Google_Service_Sheets_ValueRange();
$values->setValues(['values' => $body]);
$this->client->spreadsheets_values->update($spreadSheetId, 'A1:B2', $values, ['valueInputOption' => 'RAW']);
}
但是我越来越期待
HP Fatal error: Uncaught exception 'Google_Service_Exception' with message '{
"error": {
"code": 400,
"message": "Invalid values[0][0]: list_value {\n values {\n string_value: \"ab\"\n }\n values {\n string_value: \"cd\"\n }\n}\n",
"errors": [
{
"message": "Invalid values[0][0]: list_value {\n values {\n string_value: \"ab\"\n }\n values {\n string_value: \"cd\"\n }\n}\n",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
推荐答案
正确格式为
$body = array(
array('ab', 'cd'),
array('ef', 'gh')
);
$values = new Google_Service_Sheets_ValueRange();
$values->setValues($body);
这篇关于将值上传到Google表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文