BigQuery Ошибка InsertAll: записей в приложении данных таблицы нет

Мне кажется, что все работает, за исключением последней строки этой функции. Но кажется, что проблема json (rows) – проблема …

Любая помощь приветствуется!

Ошибка:

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 

Код:

 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); } 

Solutions Collecting From Web of "BigQuery Ошибка InsertAll: записей в приложении данных таблицы нет"

Класс Google_Service_Bigquery_TableDataInsertAllRequestRows должен быть назван _Row not _Rows, потому что вы должны сделать массив объектов _Rows для передачи запроса. Вот код, который, наконец, работал.

Кроме того, json должен быть объектом, а не json-строкой. $ data = json_decode строки json, которая была в исходном вопросе.

 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); } 

Просто хотел поделиться: я делаю небольшое изменение, потому что код выше не работал для меня: эта строка была проблемой

  $this->service->tabledata->insertAll($this->project_id, 'log', 'v1', $request); 

Проблема заключается в использовании ключевого слова $ this-> service. Это потому, что код не запускался внутри класса. Вместо $ this вы должны использовать $ service

это полный код php google bigquery auth и php google bigquery insert, который работает для меня:

  define("CLIENT_ID", 'my client id'); define('KEY_FILE','key.p12'); define('SERVICE_ACCOUNT_NAME', 'its the email address as appear on the credential page'); define('PROJECT_ID', 'my project'); define('DATASET_ID', 'my data set'); define('TABLE_ID', 'my table'); $client_id = CLIENT_ID; $service_account_name = SERVICE_ACCOUNT_NAME; //Email Address $key_file_location = KEY_FILE; // Cashing the client inside a session. $client = new Google_Client(); $client->setApplicationName("Client_Library_Examples"); if (isset($_SESSION['service_token'])) { $client->setAccessToken($_SESSION['service_token']); } else { $key = file_get_contents($key_file_location); $cred = new Google_Auth_AssertionCredentials( $service_account_name, array('https://www.googleapis.com/auth/bigquery'), $key ); $client->setAssertionCredentials($cred); $client->setClientId(CLIENT_ID); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $_SESSION['service_token'] = $client->getAccessToken(); } $service = new Google_Service_Bigquery($client); $data = array( 'fields1' => '1', 'sample' => '2','maker' => '2'); try { $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); $response = $service->tabledata->insertAll(PROJECT_ID, DATASET_ID , TABLE_ID, $request); print_r($response); } catch (Exception $ex) { echo $ex->getMessage(); } } 

Этот ответ означает, что ошибок нет. перейдите для проверки в bigQuery и посмотрите значения:

 Google_Service_Bigquery_TableDataInsertAllResponse Object ( [collection_key:protected] => insertErrors [internal_gapi_mappings:protected] => Array ( ) [insertErrorsType:protected] => Google_Service_Bigquery_TableDataInsertAllResponseInsertErrors [insertErrorsDataType:protected] => array [kind] => bigquery#tableDataInsertAllResponse [modelData:protected] => Array ( ) [processed:protected] => Array ( ) ) 

Всем удачи!