如何使用C++;还是Java控制台应用程序来操作我的云Firestore项目?
我使用Cloud Firestore为我的Android应用程序存储数据,然后我想制作一个支持工具来轻松操作我的Cloud Firestore项目。(通过网页GUI向Cloud Firestrore添加100多个固定格式的数据对我和我的手指来说太难了。) 因此,我想做一个支持工具如何使用C++;还是Java控制台应用程序来操作我的云Firestore项目?,java,google-cloud-firestore,console-application,Java,Google Cloud Firestore,Console Application,我使用Cloud Firestore为我的Android应用程序存储数据,然后我想制作一个支持工具来轻松操作我的Cloud Firestore项目。(通过网页GUI向Cloud Firestrore添加100多个固定格式的数据对我和我的手指来说太难了。) 因此,我想做一个支持工具 CSV文件(我知道如何在C++或java中实现) 连接到我的云Firestore项目 操作(添加或删除)来自CSV文件的数据 我阅读了谷歌官方的启动指南“GetStartedwithCloudFireStore”()
import com.google.auth.oauth2.GoogleCredentials;
导入com.google.cloud.firestore.firestore;
导入com.google.firebase.FirebaseApp;
导入com.google.firebase.FirebaseOptions;
导入java.io.*;
//gradle编译的以下两个包不存在。
导入com.google.firebase.cloud.*;
导入com.google.firebase.firestore.*;
公共班机{
公共静态void main(字符串参数[]){
试一试{
FirebaseOptions=newfirebaseOptions.Builder()
.setCredentials(GoogleCredentials.getApplicationDefault())
.setDatabaseUrl(“https://rikotenapp2020.firebaseio.combuild();
FirebaseApp.initializeApp(选项);
System.out.println(“没有例外!”);
Firestore db=FirestoreClient.getFirestore();
//根据我的调查,如果我删除其余代码(DocumentReference…~println();})
//我可以成功地编译它。
DocumentReference ref=db.collection(“AppVersion”).文档(“Android”);
ApiFuture=ref.get();
DocumentSnapshot document=future.get();
if(document.exists()){
System.out.println(“android应用程序版本为”+document.getData());
}否则{
System.out.println(“没有这样的文档!”);
}
}捕获(IOE异常){
System.out.println(“发生了IOException!”);
}
}
}
我设置了“Firestore管理员SDK”,我错了吗?
如果有人知道如何解决这个问题,如果你能告诉我,我很高兴得到你的宝贵建议。
这是我的第一个问题,我不是以英语为母语的人。请原谅我难以理解的问题。我现在解决它。
我应该做的是遵循官方教程()。
然而,因为我使用VisualStudio代码编辑java程序,并且我没有任何插件来适应关于外部库的“自动导入”,所以我发现这种情况是一个难题
对于其他将来到这里的人:
教程中对Java的介绍没有仔细的导入语句。解决这个问题的最佳直接方法是阅读官方参考()并在Java程序中编写导入语句。
这个问题是从我的误解开始的。我感谢所有人在这个问题上帮助我。您有什么例外或问题?我想通过这个控制台操作我的cloud firestore项目,所以我添加了这样的java代码(在注释之前)。很抱歉,我在编写时发送了。完整版本如下。我想通过这个控制台操作我的CloudFireStore项目,所以我添加了这样的java代码(在注释之前)。然而,我想在Android开发中使用时顺便从project下载一些数据(在java文件中的注释之后),但由于编译器找不到符号(可能编译器不能将DocumentReference等视为类),所以发生了编译错误。DocumentReference可能只能用于Android开发。我想知道对应的文件参考等。
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!");
}
}
}