我正在使用Google Cloud Firestore Beta,並根據Google提供的文檔編寫了一個非常簡單的代碼。我在執行它時遇到了未認證的錯誤。代碼如下,與文檔中提供的一些代碼片段非常相似。連接到Google Firestore時未經認證的問題
String keyPath = "mykeystore.json";
FirestoreOptions firestoreOptions = FirestoreOptions.getDefaultInstance().toBuilder().setProjectId("test-project-111").setCredentials(ServiceAccountCredentials.fromStream(new FileInputStream(keyPath))).build();
Firestore db = firestoreOptions.getService();
DocumentReference docRef = db.collection("users").document("alovelace");
// Add document data with id "alovelace" using a hashmap
Map<String, Object> data = new HashMap<>();
data.put("first", "Ada");
data.put("last", "Lovelace");
data.put("born", 1815);
//asynchronously write data
ApiFuture<WriteResult> result = docRef.set(data);
try
{
result.get();
} catch (InterruptedException e)
{
e.printStackTrace();
} catch (ExecutionException e)
{
e.printStackTrace();
}
I am getting the error at the "result.get()" line of the code. The error is as below:
[INFO] GCLOUD:java.util.concurrent.ExecutionException:com.google.api.gax.rpc.UnauthenticatedException:io.grpc.StatusRuntimeException:當UNAUTHENTICATED
這裏分享完整的堆棧跟蹤: –
驗證您公司的FireStore API密鑰&ID https://cloud.google.com/firestore/docs/solutions/search – 2017-10-07 23:51:37