Appsスクリプトを使用してGoogle Datastoreを試したいのですが、Googleのシートに基づいて現在の解決策があります。私はサービスアカウントを持つGoogleクラウドでテストプロジェクトを作成し、ライブラリを有効にしましたMZx5DzNPsYjVyZaR67xXJQai_d-phDA33 (cGoa)はOauth2の作業を処理します。私はhereを起動するためにガイドに従って、それが私のトークンで動作するという適切な確認をすべて得ました。そして、トークンを取り除くと '認証に失敗しました'というプロンプトが表示されます。Apps Script URLFetchAppを使用してGoogle Datastoreデータにアクセスする
今、私はAPIエクスプローラhereを使用して、このクエリ本体を実行することができます私はすでに入れ1つのエンティティを表示するには、基本的なクエリを開始したい:
{
"query": {}
}
し、この結果を得る:
。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());
}
と、この電子を得る:
{
"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"
}
}
私はこのコードで同じことをやろうロガーで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 ScriptからDatastoreへ機能的なリクエスト本体をコンパイルする方法を教えてもらえますか?
また:「エラー」:{ 空体でクエリを実行すると、この応答を作成します。 "code":400、 "message": "Query.queryとQuery.gql_queryのいずれかのフィールドを設定する必要があります"、 "ステータス": "INVALID_ARGUMENT" } } –