【发布时间】:2018-03-28 19:45:48
【问题描述】:
我正在使用 HttpsURLConnection 向 Firestore 发送 GET、POST、PATCH 和 DELETE 请求。
private static final String REST_HEADER = "https://firestore.googleapis.com/v1beta1/projects/[my project id]/databases/(default)/documents/";
// Build URL
String FirestoreURL = REST_HEADER + [my document path] + "?key=" + [my web api key];
// Create URL
URL cloudFirestoreEndPoint = new URL(FirestoreURL);
// Create connection
myHttpsConnection = (HttpsURLConnection) cloudFirestoreEndPoint.openConnection();
// Set Request Method
myHttpsConnection.setRequestMethod("PATCH");
// Set Writable
myHttpsConnection.setDoOutput(true);
// Set Https Connection properties
myHttpsConnection.setRequestProperty("Content-Type", "application/json");
// Create output stream linked to our https connection
OutputStreamWriter streamWriter = new OutputStreamWriter(myHttpsConnection.getOutputStream());
// Write to buffer
streamWriter.write([my json]);
// Send out the buffer
streamWriter.flush();
// Close the stream
streamWriter.close();
// disconnect
myHttpsConnection.disconnect();
我想知道如何设置我的 Firestore 数据库规则,以便允许任何包含正确“?key="[my web api key] 的读写请求。
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request == 'MY WEB API KEY???';
}
}
}
您将如何在 Firestore 中编写它?
【问题讨论】:
-
我也有同样的问题。你解决了吗?
-
是的,我已经更新了代码
标签: firebase https google-cloud-firestore firebase-security google-apis-explorer