邮递员Google API请求给出“ 401:未经授权”

时间:2020-08-27 15:19:17

标签: rest google-cloud-firestore google-api postman

我正在通过邮递员发送发帖请求

https://my_app_id.firebaseio.com/databases/locations/documents/123456/1598539394290.json?key=WEB_API_KEY

Json:

{"latitude":12.345678,"longitude":12.345678,"timestamp":1598539394290,"userId":"123456"}

Json“ 401 Unauthorized”出现错误{"error": "Permission denied"}

Firestore的权限:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

我之前通过Google Java SDK发送请求,一切都还可以,但现在我需要使用API​​重做一次。

请帮忙找出问题所在。

1 个答案:

答案 0 :(得分:1)

您显示的安全规则适用于Firestore,但是您使用的URL正在写入实时数据库,这是一个完全不同的数据库。实际上,您似乎在将Firestore的元素与该URL中的Realtime Database API组合在一起,这非常令人困惑。

如果要写入Firestore,则应仅使用{strong> Firestore REST API documentation忽略您在Realtime Database API documentation中看到的所有内容。