我想使用 REST API 在 Firestore 中创建一个新文档。
这里使用 Axios 发送带有某些字段的 POST 请求是非常好的示例:
https://www.jeansnyman.com/posts/google-firestore-rest-api-examples/
axios.post(
"https://firestore.googleapis.com/v1/projects/<PROJECTIDHERE>/databases/(default)/documents/<COLLECTIONNAME>",
{
fields: {
title: { stringValue: this.title },
category: { stringValue: this.category },
post: { stringValue: this.post },
summary: { stringValue: this.description },
published: { booleanValue: this.published },
created: { timestampValue: new Date() },
modified: { timestampValue: new Date() }
}
}
).then(res => { console.log("Post created") })
Run Code Online (Sandbox Code Playgroud)
这里有一个使用 Python 请求的示例:
使用 Firestore REST API 更新文档字段
(这是一个 PATCH 请求,但字段格式与 POST 请求中的相同)
import requests
import json
endpoint …Run Code Online (Sandbox Code Playgroud) google-apps-script python-requests firebase axios google-cloud-firestore