我想通過Apps腳本試用Google數據存儲,因爲我有一個基於Google工作表的當前解決方案,該解決方案遇到了與Drive文件不斷交易時固有的超時問題。我使用服務帳戶在Google雲中創建了一個測試項目,並啓用了庫MZx5DzNPsYjVyZaR67xXJQai_d-phDA33 (cGoa)來處理Oauth2工作。我按照指南啓動它here並得到了與我的令牌一起工作的所有相關確認(並且刪除令牌會引發'驗證失敗提示')。使用應用腳本URLFetchApp訪問Google數據存儲數據
現在我要開始一個基本的查詢,顯示我已經放在一個實體,我可以使用API瀏覽器here並運行此查詢的身體:
{
"query": {}
}
,並得到這樣的結果:
{
"batch": {
"entityResultType": "FULL",
"entityResults": [
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707333336492774"
},
"path": [
{
"kind": "Transaction",
"id": "5629499534213120"
}
]
},
"properties": {
"CommentIn": {
"stringValue": "My First Test Transaction"
},
"Status": {
"stringValue": "Closed"
},
"auditStatus": {
"stringValue": "Logged"
},
"User": {
"stringValue": "John Doe"
},
"Start": {
"timestampValue": "2017-08-17T18:07:04.681Z"
},
"CommentOut": {
"stringValue": "Done for today!"
},
"End": {
"timestampValue": "2017-08-17T20:07:38.058Z"
},
"Period": {
"stringValue": "08/16/2017-08/31/2017"
}
}
},
"cursor": "CkISPGogc35whh9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyGAsSC1RyYW5zYWN0aW9uGICAgICAgIAKDBgAIAA=",
"version": "1503004124243000"
}
],
"endCursor": "CkISPGogc35wcm9qZWN0LWlkLTUyMDAxxDcwODA1MDY0OTI3NzRyGAsSC1RyYW5zYWN0aW9uGICAgICAgIAKDBgAIAA=",
"moreResults": "NO_MORE_RESULTS"
}
}
我嘗試做同樣的事情,此代碼:
function doGet(e)
{
var goa = cGoa.GoaApp.createGoa('Oauth2-Service-Account',
PropertiesService.getScriptProperties()).execute(e);
if(goa.hasToken()) {var token = goa.getToken();}
var payload = {"query":{}}
;
var result = UrlFetchApp.fetch('https://datastore.googleapis.com/v1/projects/project-id-5200707333336492774:runQuery',
{
method: "POST",
headers: {authorization: "Bearer " + goa.getToken()},
muteHttpExceptions : true,
payload: payload
});
Logger.log(result.getBlob().getDataAsString());
}
,並得到這個電子RROR在記錄器:
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"query\": Cannot bind query parameter. 'query' is a message type. Parameters can only be bound to primitive types.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"query\": Cannot bind query parameter. 'query' is a message type. Parameters can only be bound to primitive types."
}
]
}
]
}
}
如果我嘗試用另一個詞,如「資源」或「GqlQuery」,我得到這個錯誤:
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"GqlQuery\": Cannot bind query parameter. Field 'GqlQuery' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"GqlQuery\": Cannot bind query parameter. Field 'GqlQuery' could not be found in request message."
}
]
}
]
}
}
我無法從API文檔告訴我的語法應該是什麼。任何人都可以告訴我如何編寫一個功能請求體從Apps腳本到數據存儲?
另外:運行一個空的身體查詢創建此迴應:「錯誤」:{ 「代碼」:400, 「消息」:「必須設置Query.query和Query.gql_query字段之一」, 「status」:「INVALID_ARGUMENT」 } } –