1

enter image description here

I am trying to get data from Firebase's Realtime database. In my database, I have a node named users. Under that, I have the UUID of All users. I want to get all UUIDs. I tried with unity Restclient API. And the result was an empty thing.

my code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Models;
using Proyecto26;
using UnityEngine.Networking;
    
        public class AdminPanel : MonoBehaviour
        {
            public GameObject manager;
            public string idToken,localId;
        
            public string databaseURL = "https://xxx.firebaseio.com/"; 
        
            private void LogMessage(string title, string message) {
            #if UNITY_EDITOR
                EditorUtility.DisplayDialog (title, message, "Ok");
            #else
                Debug.Log(message);
            #endif
            }
            void Start()
            {
                idToken = manager.GetComponent<SignUpData>()._idToken;
                localId = manager.GetComponent<SignUpData>()._localId;
            }
            public void GetData()
            {
                RestClient.GetArray<users>(databaseURL + "users" +".json?auth=" + idToken).Then(res => {
                    this.LogMessage("Users", JsonHelper.ArrayToJsonString<users>(res, true));
                }).Catch(err => this.LogMessage("Error", err.Message));
            }
        }
Savad
  • 1,240
  • 3
  • 21
  • 50
  • Since you're working inside Unity, you probably want to be using the Firebase SDK for Unity and not the Rest API: https://firebase.google.com/docs/database/unity/retrieve-data – NSJacob1 Sep 08 '22 at 02:25
  • Its Actually WebGL project – Savad Sep 09 '22 at 05:46
  • In that case you may want to refer to this post: https://stackoverflow.com/questions/46216440/firebase-in-unity-webgl-build#60883058 – NSJacob1 Sep 09 '22 at 16:01
  • I'm not sure why your solution in particular doesn't work, but it may be related to why the Firebase SDK for Unity also doesn't support WebGL target. I would try using the Rest API through JS bindings as suggested in the linked post. – NSJacob1 Sep 09 '22 at 16:04

0 Answers0