Luk*_*aus 6 api rest timestamp google-cloud-firestore
我正在尝试通过 REST API(https://developers.google.com/apis-explorer/#search/firestore/firestore/v1beta1/firestore.projects.databases.documents.createDocument)将数据添加到 Cloud Firestore
我能够创建一个新文档,例如一个整数值,所以连接和语法似乎没问题。
在下一步中,我想将服务器端时间戳添加到文档中。因为我从 ESP32 发出 POST-Request 并且时间不可用。请求体看起来像:
{
"fields":{
"myTime":{
"timestampValue":"SERVER_TIME_STAMP"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我必须为 SERVER_TIME_STAMP 写什么?对于其他语言,似乎有一个像firebase.database.ServerValue.TIMESTAMP这样的常量,服务器将用其当前时间替换它。但是 API 不接受像 thees 这样的值。
错误消息是
"code": 400,
"message": "Invalid value at 'document.fields[0].value.timestamp_value' (type.googleapis.com/google.protobuf.Timestamp), Field 'timestampValue', Illegal timestamp format; timestamps must end with 'Z' or have a valid timezone offset.",
Run Code Online (Sandbox Code Playgroud)
对于 REST API,您应该使用DocumentTransform-> FieldTransform-> setToServerValue-> set ServerValueas REQUEST_TIME。
似乎DocumentTransform只能在writeand commitAPI 上使用,而不能createDocument在 or 上使用patch。您可以使用commitAPI 来代替patch.
https://firebase.google.com/docs/firestore/reference/rest/v1beta1/Write#ServerValue
| 归档时间: |
|
| 查看次数: |
1299 次 |
| 最近记录: |