如何为 Firebase Firestore rest api 调用提供身份验证数据

How do I provide auth data for Firebase Firestore rest api call

这是我的 REST API 获取:https://firestore.googleapis.com/v1beta1/projects/{myProjectId}/databases/(default)/documents/books

我的目标当然是从我的 books collection 中检索文档。 REST API 文档不是很好。我了解如何在给定 Firestore 范围的情况下获得 access_token,但我实际上如何在 GET 中提供它? Bearer {access_token}Authorization header 一样吗?我还提供 api={apiKey} 作为查询字符串参数吗?谢谢。

您只需添加 authorization header。这是一个 curl 相同的请求:

curl --request GET \
  --url 'https://firestore.googleapis.com/v1beta1/projects/[PROJECT_ID]/databases/(default)/documents/books' \
  --header 'authorization: Bearer [ACCESS_TOKEN]'

如果您仍然收到 403 - Forbidden 错误,则令牌可能已过期或安全规则不允许读取操作。