简体   繁体   English

如何使用 C++ 或 Java Console Application 来操作我的 Cloud Firestore 项目?

[英]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因此,我想制作一个支持工具

  1. read CSV file(I know how to do this in C++ or Java)读取 CSV 文件(我知道如何在 C++ 或 Java 中执行此操作)
  2. connect to my Cloud Firestore project连接到我的 Cloud Firestore 项目
  3. operate(add or erase) data deriving from CSV file.操作(添加或删除)来自 CSV 文件的数据。

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 ),并做了以下事情。

  1. install gradle安装gradle
  2. Set User environment variable in following sentence.(the location is the secret json file made by Cloud Firestore Service Account.)在下面的句子中设置用户环境变量。(位置是 Cloud Firestore 服务帐户制作的秘密 json 文件。)
GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\service-account-file.json"
  1. write "build.gradle" as following sentence.将“build.gradle”写成以下句子。
    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'
    }
  1. write following java file.编写以下java文件。
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.

相关问题 如何从我的Java应用程序中与C控制台应用程序进行交互 - How to interact with a C console application from within my Java application 如何使用C ++应用程序和系统功能执行Java控制台应用程序? - How can I execute a java console application by using a C++ application and the system function? 如何使用 Firebase 模拟器通过 Firestore 触发器测试 Java 云功能? - How to use Firebase emulator to test Java cloud functions with Firestore trigger? 如何在云中运行使用套接字的Java控制台应用程序? - How to run a Java console application that uses Sockets in the cloud? 如何将我的BlueJ项目转换为可以在控制台中运行的应用程序 - How To Turn My BlueJ Project Into a Application That Can Run In Console 如何将我的Java项目转换为桌面应用程序? - How to convert my Java project into a Desktop Application? 如何在C ++应用程序中访问Java方法 - How to access the Java method in a C++ application 如何将C ++集成到Android Java应用程序中? - How to integrate C++ into Android Java application? 如何在Cloud Firestore中使用startAt()和endAt()? - How to use startAt() and endAt() in Cloud Firestore? 如何在C ++应用程序中使用Solr - how to use solr with a c++ application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM