Reputation: 543
I am using postman to get data from my firestore api
https://firestore.googleapis.com/v1beta1/projects/myapp-ef511/databases/countries
but I am getting this,although my rules are public
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
How can I achieve this?I am planning to use retrofit in future.
Upvotes: 12
Views: 18003
Reputation: 311
your rules maybe like this
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2021, 1, 15);
}
}
}
change to
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
this work for me
Upvotes: 1
Reputation: 1677
Go to Firebase console and follow the below steps.
In General tab -> Under 'Your project' section it will show Project ID & Web API Key (will use it in url)
Now go to your Firestore database and get the document name e-g users
Finally just hit the below url with your desired values of Project ID, Web API Key and Document
https://firestore.googleapis.com/v1/projects/[Project ID]/databases/(default)/documents/[Document]?key=[Web API Key]
Example of real url:
https://firestore.googleapis.com/v1/projects/firestore-rest-api-test/databases/(default)/documents/players?key=AIzaSyDsCtB9PiFTtkJiDRmFEakbKvoohPRAGJU
NOTE: make sure you set your project rules on test mode to make it work. Otherwise use authentication first to make it work
Upvotes: 20
Reputation: 6854
The REST API requires either a Firebase Authentication ID token or Google Identity OAuth 2.0 token. The main difference between the two is that a Firebase Auth ID applies security rules and the Google ID does not. This guide on working with the Firestore REST API should help.
Upvotes: 5