简体   繁体   English

如何将我的 MAUI 应用程序连接到生产环境中的 Firestore 数据库?

[英]How do I connect my MAUI app to a Firestore database in production?

I'm creating a MAUI app and I'm trying to connect it to Firestore.我正在创建一个 MAUI 应用程序,并尝试将其连接到 Firestore。 I have set everything up in Firebase and I can successfully connect to the Firestore by setting the environment variable: "GOOGLE_APPLICATION_CREDENTIALS" on my windows machine locally.我已经在 Firebase 中设置了所有内容,并且可以通过在本地 windows 机器上设置环境变量:“GOOGLE_APPLICATION_CREDENTIALS”来成功连接到 Firestore。

However, I cannot make it work if I test out the app using my local android device since this device doesn't have the environment variable set up.但是,如果我使用本地 android 设备测试应用程序,我无法使其工作,因为该设备没有设置环境变量。

So my question is, how would I go about doing this, so I can connect to the Firestore on my android device?所以我的问题是,我将如何 go 这样做,所以我可以连接到我的 android 设备上的 Firestore?

Some thoughts:一些想法:

  1. I would imagine that I need to set the environment variable in the MAUI code and somehow read it, but wouldn't that expose the secret file since it would now exist inside the MAUI project?我想我需要在 MAUI 代码中设置环境变量并以某种方式读取它,但这不会暴露秘密文件,因为它现在存在于 MAUI 项目中吗?

  2. It looks like some people are using the google-services.json file for this purpose (which is not strictly secret) so if I could use that instead, then I guess that would be the best, but again, how would I do that?看起来有些人为此目的使用了 google-services.json 文件(这不是严格保密的),所以如果我可以使用它,那么我想那将是最好的,但我又该怎么做呢?

  3. I have tried adding the files in the Asset files, .csproj file, setting environment variables in the MainProgram etc. but I just can't make it work and even worse, I'm unsure whether that approach would be insecure.我尝试在资产文件、.csproj 文件中添加文件,在 MainProgram 中设置环境变量等,但我无法让它工作,更糟糕的是,我不确定这种方法是否不安全。

Any help would be greatly appreciated.任何帮助将不胜感激。

Possible duplicate: How do I connect my MAUI app to a Firestore database?可能重复: 如何将我的 MAUI 应用程序连接到 Firestore 数据库? (via service account json file) (通过服务帐户 json 文件)

I just still don't understand how they made it work.我只是仍然不明白他们是如何让它工作的。

This is how I successfully set it up in .NET Maui:这就是我在 .NET Maui 中成功设置它的方式:

  1. Copy the "Json" file from Google under the "Resource/Raw" folder with a BuildAction "MauiAsset"使用 BuildAction“MauiAsset”从 Google 复制“Resource/Raw”文件夹下的“Json”文件
  2. Below is my initialization code:下面是我的初始化代码:
        public async Task<FirestoreDb> initFirestore()
        {
            try
            {
                var stream = await FileSystem.OpenAppPackageFileAsync(Constants.FirestoreKeyFilename);
                var reader = new StreamReader(stream);
                var contents = reader.ReadToEnd();

                FirestoreClientBuilder fbc = new FirestoreClientBuilder { JsonCredentials = contents };
                return FirestoreDb.Create(Constants.FirestoreProjectID, fbc.Build());
            }
            catch (Exception)
            {
                throw;
            }
        }

Hope that helps.希望有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我的后端是 firebase firestore,我如何在我的 react js 应用程序中使用 JWT - How do i use JWT in my react js app, if my backend is firebase firestore Firestore:如何更新 email 并将其作为单个批处理操作存储在我的 Firestore 集合中? - Firestore: How do I update email and store it in my firestore collection as a single batch operation? 当我在 flutter firestore 中打开互联网时,我如何知道我在离线模式下对文档所做的所有更改都同步到了 firestore - How do i know all my changes made to document in offline mode are synced to firestore when i turn on internet in flutter firestore 如何在 Firestore 中实施数据库模式? - How can I enforce database schema in Firestore? 如何检索作为文档放置在 Firebase Cloud Firestore 中的 UID - How do I retrieve the UID's that I have placed as documents in my Firebase Cloud Firestore 如何使用 flutter 中的 JSONserializable 在 Cloud Firestore 数据库中设置嵌套字段 - How do I set up a nested field in a Cloud Firestore database using JSONserializable in flutter Firebase:如何在应用检查中注册我的 Flutter 应用? - Firebase: How do I register my Flutter app in app check? 如何将我的 react 原生网站链接到我的应用程序? - How do I link my react native website to my app? 我将如何显示来自我的 Firestore 的帖子? - How would I show my posts from my firestore? 如何仅启用对我的 nativescript 应用程序的 firestore 数据访问? - How to enable access of firestore data to my nativescript app only?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM