将Firebase Admin SDK添加到Unity项目 [英] Adding Firebase Admin SDK to Unity project

查看:70
本文介绍了将Firebase Admin SDK添加到Unity项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Unity以及C#(C#的真正菜鸟和所有.NET东西)都是陌生的,我想在Unity项目中使用Firebase Realtime Database.我正在按照

现在,我不知道如何将Admin SDK添加到我的Unity项目中.我只能找到有关如何将Admin SDK添加到服务器的引用.但是如何将Admin SDK添加到Unity项目中?

解决方案

我写了一封邮件给Firebase支持,甚至在Firebase Community Slack频道和 NuGet 插件,然后搜索了Firebase Admin SDK(已安装SDK)当然也是)

  • 我按照此处的说明进行操作,并将代码段复制到了我的项目:
  •   FirebaseApp.Create(new AppOptions(){凭据= GoogleCredential.GetApplicationDefault(),}); 

    重要:复制代码段并导入依赖项后,我的IDE导入了 Firebase 包而不是 FirebaseAdmin 包无效,并且 Credential 参数在 AppOptions 中找不到.因此,请确保使用正确的依赖项.

    I'm new to Unity as well as to C# (real noob to C# and all the .NET stuff) and I want to use the Firebase Realtime Database in my Unity project. I was following the instructions on the Firebase docs to set things up, but after I created a new p12 file and added this code to my project

      void Start() {
        // Set these values before calling into the realtime database.
        FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://YOUR-FIREBASE-APP.firebaseio.com/");
        FirebaseApp.DefaultInstance.SetEditorP12FileName("YOUR-FIREBASE-APP-P12.p12");
        FirebaseApp.DefaultInstance.SetEditorServiceAccountEmail("SERVICE-ACCOUNT-ID@YOUR-FIREBASE-APP.iam.gserviceaccount.com");
        FirebaseApp.DefaultInstance.SetEditorP12Password("notasecret");
      }
    

    I got the following hint:

    Method 'Firebase.Unity.Editor.FirebaseEditorExtensions.SetEditorP12FileName' is obsolete: Service account in editor is no longer supported. Please use standard sign-in methods instead, ex. FirebaseAuth.SignInWithEmailAndPasswordAsync()

    This brought me to the Firebase Deprecated page which says:

    Now I don't know how to add the Admin SDK to my Unity project. I can only find references about how to add the Admin SDK to a server. But how can I add the Admin SDK to an Unity project?

    解决方案

    I wrote a mail to the Firebase Support and even wrote in the Firebase Community Slack channel and the reference on how to add the Admin SDK to a server seems to be the way to go for unity projects as well.

    Here is what I did (in case someone want to save some time):

    1. I installed the NuGet plugin for Unity and then searched for the Firebase Admin SDK (installed the SDK of course as well)
    2. I followed the instructions here and copied the code snippet into my project:

    FirebaseApp.Create(new AppOptions()
    {
        Credential = GoogleCredential.GetApplicationDefault(),
    });
    

    Important: after copying the code snippet and importing the dependencies, my IDE imported the Firebase package instead of the FirebaseAdmin package which of course don't work and the parameter Credential can't be found as part of AppOptions. So make sure to use the correct dependency.

    这篇关于将Firebase Admin SDK添加到Unity项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆