Firestore REST API添加时间戳 [英] Firestore REST API add Timestamp
问题描述
我正在尝试通过REST API( 我必须为SERVER_TIME_STAMP写什么?对于其他语言,似乎有一个常量,例如 firebase.database.ServerValue.TIMESTAMP ,服务器将用其当前时间替换该常量.但是API不接受像thees这样的值. 错误消息是
对于REST API,您应使用 好像 https://firebase.google.com/docs/firestore/reference/rest/v1beta1/Write#ServerValue I am trying to add Data to Cloud Firestore via the REST API (https://developers.google.com/apis-explorer/#search/firestore/firestore/v1beta1/firestore.projects.databases.documents.createDocument) I am able to create a new Document with e.g. an Integer Value, so the connection and the syntax seems to be ok. In the next step I want to add the server side timestamp to the document. Because I make the POST-Request from an ESP32 and the time is not available. The Request-Body looks like: What do I have to write for SERVER_TIME_STAMP? For other languages there seems to be an Constant like firebase.database.ServerValue.TIMESTAMP that the server will replace with its current time. But the API does not accept values like thees. The Error-msg is
For REST API, you should use Seems like https://firebase.google.com/docs/firestore/reference/rest/v1beta1/Write#ServerValue 这篇关于Firestore REST API添加时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!"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.",
DocumentTransform
-> FieldTransform
-> setToServerValue
->将ServerValue
设置为REQUEST_TIME
. >
DocumentTransform
似乎只能在write
和commit
API上使用,而不能在createDocument
或patch
上使用.您可以使用commit
API代替patch
.{
"fields":{
"myTime":{
"timestampValue":"SERVER_TIME_STAMP"
}
}
}
"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.",
DocumentTransform
-> FieldTransform
-> setToServerValue
-> set ServerValue
as REQUEST_TIME
.DocumentTransform
is only available for use on write
and commit
API and not createDocument
or patch
. You can use commit
API as a substitute of patch
.