BigQuery [PHP] InsertAll Error:表数据附加请求中没有记录

mic*_*rry 5 php google-bigquery

除了这个函数的最后一行,我觉得一切都在工作.但似乎json(行)是问题......

任何帮助表示赞赏!

错误:

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.
Run Code Online (Sandbox Code Playgroud)

表格架构:

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
Run Code Online (Sandbox Code Playgroud)

码:

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);
}
Run Code Online (Sandbox Code Playgroud)

mic*_*rry 4

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);
}
Run Code Online (Sandbox Code Playgroud)