在我看来,除了这个函数的最后一行之外,一切都正常。但似乎 json(行)是问题所在......
任何帮助表示赞赏!
Error:
Google_Service_Exception
Error calling POST https://www.googleapis.com/bigquery/v2/projects/mtg/datasets/log/tables/v1/insertAll: (400) No records present in table data append request.
表架构:
raw_url STRING NULLABLE
endpoint STRING NULLABLE
parameter STRING NULLABLE
client_ip STRING NULLABLE
account INTEGER NULLABLE
response_code INTEGER NULLABLE
response_time INTEGER NULLABLE
datetime TIMESTAMP NULLABLE
Code:
public function insertLog()
{
$rows = new Google_Service_Bigquery_TableDataInsertAllRequestRows;
$rows->setJson('{"raw_url":"test","endpoint":"card.id","parameter":"1","client_ip":"127.0.0.1","account":1,"response_code":200,"response_time":1000,"created_at":"2014-02-14 19:16:21"}');
$rows->setInsertId("21");
$request = new Google_Service_Bigquery_TableDataInsertAllRequest;
$request->setKind('bigquery#tableDataInsertAllRequest');
$request->setRows($rows);
$this->service->tabledata->insertAll($this->project_id, 'log', 'v1', $request);
}
Google_Service_Bigquery_TableDataInsertAllRequestRows 类应命名为 _Row 而不是 _Rows,因为您必须创建一个 _Rows 对象数组来传递请求。这是最终起作用的代码。
另外,json 必须是对象,而不是 json 字符串。 $data = 原始问题中的 json 字符串的 json_decode。
public function insertLog($data)
{
$rows = array();
$row = new Google_Service_Bigquery_TableDataInsertAllRequestRows;
$row->setJson($data);
$row->setInsertId( strtotime('now') );
$rows[0] = $row;
$request = new Google_Service_Bigquery_TableDataInsertAllRequest;
$request->setKind('bigquery#tableDataInsertAllRequest');
$request->setRows($rows);
$this->service->tabledata->insertAll($this->project_id, 'log', 'v1', $request);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)