[英]How to use C++ or Java Console Application to operate my Cloud Firestore project?
I use Cloud Firestore to store data for my Android application, then I want to make a supporting tool to operate my Cloud Firestore project easily.(It is too hard and bore for me and my fingers to add more 100 datas in a constant format to Cloud Firestrore by Webpage GUI.)我使用 Cloud Firestore 为我的 Android 应用程序存储数据,然后我想制作一个支持工具来轻松操作我的 Cloud Firestore 项目。网页 GUI 的 Cloud Firestrore。)
Therefore, I want to make a support tool to因此,我想制作一个支持工具
I read Google Official start up guide "Get started with Cloud Firestore"( https://firebase.google.com/docs/firestore/quickstart#java_1 ), and did following things.我阅读了 Google 官方启动指南“开始使用 Cloud Firestore”( https://firebase.google.com/docs/firestore/quickstart#java_1 ),并做了以下事情。
GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\service-account-file.json"
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'Main'
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.firebase:firebase-admin:6.11.0'
implementation 'com.google.firebase:firebase-firestore:21.2.1'
}
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.Firestore;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import java.io.*;
//the following two package does not exist, by gradle's compiling.
import com.google.firebase.cloud.*;
import com.google.firebase.firestore.*;
public class Main {
public static void main(String args[]) {
try {
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.getApplicationDefault())
.setDatabaseUrl("https://rikotenapp2020.firebaseio.com").build();
FirebaseApp.initializeApp(options);
System.out.println("no exception!");
Firestore db = FirestoreClient.getFirestore();
//from my survey, if I erase the rest code(DocumentReference...~println();})
//I can compile it successfully.
DocumentReference ref = db.collection("AppVersion").document("Android");
ApiFuture<DocumentSnapshot> future = ref.get();
DocumentSnapshot document = future.get();
if (document.exists()) {
System.out.println("android app version is " + document.getData());
} else {
System.out.println("No such document!");
}
} catch (IOException e) {
System.out.println("IOException happened!");
}
}
}
I set up "Firestore Admin SDK", was I wrong?我设置了“Firestore Admin SDK”,我错了吗? If someone know how to resolve this, I'm very glad to get your valuable advices if you can tell me.如果有人知道如何解决这个问题,如果你能告诉我,我很高兴得到你的宝贵建议。 This is my first question, and I'm not native English speaker.Please forgive my hard-understand question.这是我的第一个问题,我的母语不是英语。请原谅我难以理解的问题。
I resolve it now.我现在解决了。 What I should do is doing following official tutorial( https://firebase.google.com/docs/firestore/quickstart ).我应该做的是遵循官方教程( https://firebase.google.com/docs/firestore/quickstart )。 However, because I use Visual Studio Code to edit java program, and I don't have any plugin to adapt "Auto Import" about external library, I found this situation as a hard problem.但是,由于我使用 Visual Studio Code 来编辑 java 程序,并且我没有任何插件来适应有关外部库的“自动导入”,因此我发现这种情况是一个难题。
For other people who will come here: The introduction of Java in tutorial doesn't have careful import sentence.对于其他会来这里的人:教程中的Java介绍没有仔细的导入语句。 The best and direct way to resolve it is reading official reference( https://googleapis.dev/java/google-cloud-firestore/latest/index.html ) and write in your java program with import sentences.解决它的最好和直接的方法是阅读官方参考( https://googleapis.dev/java/google-cloud-firestore/latest/index.html )并用导入语句在你的java程序中写入。
This question is starting from my misunderstanding.这个问题是从我的误解开始的。 I appreciate all people to help me about this problem.我感谢所有帮助我解决这个问题的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.