使用Google API Explorer时出错400

时间:2017-06-19 03:02:27

标签: google-apis-explorer

使用Google API Explorer插入GCP的数据存储区时出现以下错误。

我尝试过使用其他名称和ID,但仍然是错误。我该如何纠正这个问题?

以下是请求正文和错误。

{
    "mode": "Transactional",
    "mutations": [
        {
            "insert": {
                "key": {
                    "path": [
                        {
                            "id": "56294995342131231",
                            "name": "CL-001",
                            "kind": "Log"
                        }
                    ],
                    "partitionId": {
                        "namespaceId": "",
                        "projectId": "triplog-169706"
                    }
                },
                "properties": {
                    "Title": {
                        "stringValue": "Space Needle"
                    },
                    "Longitude": {
                        "doubleValue": 0.00
                    },
                    "Latitude": {
                        "doubleValue": 0.00
                    },
                    "Date": {
                        "timestampValue": "2015-07-03T10:51:50.649Z"
                    },
                    "Rating": {
                        "integerValue": "5"
                    },
                    "Notes": {
                        "stringValue": "Wonderful site to see"
                    }
                }
            }
        }
    ]
}


{
    "error": {
        "code": 400,
        "message": "Invalid value at 'mutations[0].insert.key.path[0]' (oneof), oneof field 'id_type' is already set. Cannot set 'name'",
        "status": "INVALID_ARGUMENT",
        "details": [
            {
                "@type": "type.googleapis.com/google.rpc.BadRequest",
                "fieldViolations": [
                    {
                        "field": "mutations[0].insert.key.path[0]",
                        "description": "Invalid value at 'mutations[0].insert.key.path[0]' (oneof), oneof field 'id_type' is already set. Cannot set 'name'"
                    }
                ]
            }
        ]
    }
}

2 个答案:

答案 0 :(得分:0)

根据文档,看起来你应该只设置一个" name"或" id"在路径元素中,而不是两者。

https://cloud.google.com/datastore/docs/reference/rest/v1/Key#PathElement

答案 1 :(得分:0)

我终于明白了。 要获得"事务",只需运行beginTransaction API。

POST https://datastore.googleapis.com/v1/projects/ {projectId}:beginTransaction

这将使用标识符进行响应,该标识符是一个长字符串。将其用作"交易的价值"。