2014-05-12 80 views
1

一直在努力與此..... Google Apps腳本和大查詢API運行良好,但是當我嘗試使用BigQuery.Tabledata.insertAll我不斷收到錯誤說'沒有這樣的領域'。Google Apps腳本和大查詢 - tabledate.insertAll

當我嘗試通過Google API瀏覽器運行相同的東西時,它工作正常。該文件說,該命令是:

BigQuery.TableData.insertAll(TableDataInsertAllRequest resource, String projectId, String datasetId, String tableId) 

我已經構建了TableDataInsertAllRequest資源按文件https://developers.google.com/bigquery/docs/reference/v2/tabledata/insertAll,它看起來像這樣:

{ 
    "kind": "bigquery#tableDataInsertAllRequest", 
    "rows": 
    [ 
    { 
     "json": 
     { 
     "domain": "test", 
     "kind": "another test" 
     } 
    } 
    ] 
} 

這是我的表模式相匹配。

當我運行命令返回的錯誤是:

{ 
    "insertErrors": [ 
     { 
      "index": 0, 
      "errors": [ 
       { 
        "message": "no such field", 
        "reason": "invalid" 
       } 
      ] 
     } 
    ], 
    "kind": "bigquery#tableDataInsertAllResponse" 
} 

正如我說的一樣TableDataInsertAllRequest資源的API資源管理器工作正常(點擊嘗試它上面的文檔頁面上),它只是不工作,通過Apps腳本。

任何幫助感激地收到。

+0

請張貼您的架構,並失敗的作業ID。 – Pentium10

回答

1

我也遇到過這種情況,並且在這種變化方面運氣好一些。

var rowObjects = []; 
// Generally you'd do this next bit in a loop 
var rowData = {}; 
rowData.domain = 'test'; 
rowData.kind = 'another test'; 
rowObjects.push(rowData); 
// And at this point you'd have an array rowObjects with a bunch of objects 
var response = BigQuery.TableData.insertAll({'rows': rowObjects}, projectId, datasetId, tableId); 

需要注意以下幾點:

  • 我並不表明kind - 它被調用暗示insertAll()
  • 我用點號(是正確的術語?)而不是字符串將屬性填充到我的「行對象」中

我不確定這些中的哪一個是Secret Sauce。無論如何,最後,通話結構看起來像這樣:

BigQuery.TableData.insertAll({'rows' : [ 
             { 
              'domain' : 'test', 
              'kind' : 'another test' 
             } 
             ] 
           }, 
           projectId, 
           datasetId, 
           tableId);