react – Exibir informações de uma coleção especifica no Firebase usando ReactJS

Boa noite, estou tentando exibir algumas informações de uma coleção no firebase porem não consigo exibir essas informações, eu estou passando um ID da coleção e está retornando no log os dados que eu quero porem não consigo exibir no navegador em html essas informações.

        useEffect(()=>{
    // retrieve a document
    const chama = firebase.firestore().collection('cursos')
    chama.doc(id)
    .get()
    .then(snapshot => {
    const document = snapshot.data()
    // do something with document
    console.log(document);
    })
    }, ())

inserir a descrição da imagem aqui

unity – Retrieving an array of images from Firebase Storage

As title says I’m trying to get all images on firebase storage and save them to an array which later on i will be using to load them into the scene. i can manage downloading on image so far but I’m unsure of how to make them into an array.

This is the code I’m using now to download one image by name and assigning it into a texture variable

        storage = FirebaseStorage.DefaultInstance;
        storageRef = storage.GetReferenceFromUrl(_url);

        storageRef.Child(_resourceName).GetBytesAsync(1024* 1024).ContinueWithOnMainThread(task =>
        {
            if (task.IsCompleted)
            {
                Texture2D texture = new Texture2D(1, 1);
                byte() fileContent = task.Result;

                texture.LoadImage(fileContent);
                Debug.Log(texture.name.ToString());
                selectedText = texture;
            }
            if (task.IsFaulted)
            {
                Debug.Log("faulted DOWNLOAD");
            }

        });

now through that i want to replace my current function which loads all images through the inspector.

 if (LevelSystemManager.Instance.CurrentLevel < source.Length)
        {
            selectedText = source(LevelSystemManager.Instance.CurrentLevel);
        }

Source being the array i use from the inspector to load those images into the game scene which then are selected into the selectedTex Texture2D and loaded based on the level, so 0 element in array == level0 , 1 == level 1 etc. etc.

So i was wondering if i have a couple of folders inside firebase with 10 to 20 images each how can i make that source array pull from that folder? And as a result remove the need to have them in the game and of course not setting them through the inspector.

Order by points in Firebase

I’m having an Android app with a point system. I would like to order the list by points. Maximum the point will be on first.

Can Anyone help me? Thanks.

java – How do I allow my application to choose a file from Google drive and upload it to Firebase?

I have an Android application that I worked on through Android Studio, I face one problem, which is when selecting a file from Google Drive, the application logs out and stops working, how can I allow the customer to choose a file from Google Drive and upload to Firebase

unity – Deserialization of JSON from Firebase to load data

i was wondering if you could help me with an issue i have with firebase and databases!
I have a class that saves variables into an array. i have managed to send that json file to firebase and i can debug it to see its correct when i load the games database but i cannot set those variables to the game. the class is like this :

   (System.Serializable)
   public class LevelItem
   {
       public bool unlocked;
       public int starAchieved;
   }
   (System.Serializable)
   public class LevelData
   {
       (Header("Primary Set"))
       public int lastUnlockedLevel = 0;
       public LevelItem() levelItemArray;
   }

to save it to firebase i do this

string levels = JsonUtility.ToJson(LevelSystemManager.Instance.LevelData);
reference.Child(data).Child("Sets").Child("Art").SetValueAsync(levels);

and i am trying to retrieve it and set those values (lastUnlocked , star achieved , unlocked and the levelItemArray) back to the game. my other variables like difficulty work fine with this :

LevelSystemManager.Instance.Bundles.difficulty = int.Parse(snapshot.Child("Settings").Child("Difficulty").GetRawJsonValue());

but i cannot load the whole levelData class back to the game! any tips or help?
when i was saving the json localy i was doing it like this to load the values

string levelDataString = System.IO.File.ReadAllText(Application.persistentDataPath + "/LevelData.json");
LevelData levelData = JsonUtility.FromJson<LevelData>(levelDataString);
if (levelData != null)
     {
LevelSystemManager.Instance.LevelData.levelItemArray = levelData.levelItemArray;
LevelSystemManager.Instance.LevelData.lastUnlockedLevel = levelData.lastUnlockedLevel;
}

but this approach wont work with firebase

i did come close i think by doing this , in which the debug does show the json in the console.

var json = snapshot.Child("Sets").Child("Art").GetRawJsonValue();
LevelData levelData = JsonUtility.FromJson<LevelData>(json);
Debug.Log(json);
 
LevelSystemManager.Instance.LevelData.levelItemArray = levelData.levelItemArray;
LevelSystemManager.Instance.LevelData.lastUnlockedLevel = levelData.lastUnlockedLevel;

but this gives an error ArgumentException: JSON must represent an object type. but when i do save it localy everything works out

The JSON that gets saved localy is this one

{"lastUnlockedLevel":1,"levelItemArray":({"unlocked":true,"starAchieved":1},{"unlocked":true,"starAchieved":0},{"unlocked":false,"starAchieved":0},{"unlocked":false,"starAchieved":0},{"unlocked":false,"starAchieved":0},{"unlocked":false,"starAchieved":0},{"unlocked":false,"starAchieved":0},{"unlocked":false,"starAchieved":0},{"unlocked":false,"starAchieved":0},{"unlocked":false,"starAchieved":0})}

and this is the one that gets saved on firebase

{
  "Purchases" : {
    "allsets" : 0,
    "animalSet" : 0,
    "architecture" : 0,
    "nature" : 0,
    "noAds" : 0,
    "technology" : 0,
    "vehicles" : 0
  },
  "Sets" : {
    "Art" : "{"lastUnlockedLevel":1,"levelItemArray":({"unlocked":true,"starAchieved":3},{"unlocked":true,"starAchieved":0})}"
  },
  "Settings" : {
    "Difficulty" : 1
  }
}

As you can see i do have more classes saved there which like my difficulty example work just fine . my whole issue is that i cannot load back the entire LevelData Class and set it to the games variables.Thank you!

unity – Saving JSON to firebase

I want to integrate Firebase to my android/iOS game. So far in production I used JSON to save a class into the devices PersistentDataPath and load them accordingly. I did follow the firebase instructions , I implemented analytics and installed the necessary packages but I’m having some trouble understanding how to convert my save system to work with it.

I’m using this class to store the information i need saved

 (System.Serializable)
    public class LevelData
    {
        (Header("Primary Set"))
        public int lastUnlockedLevel = 0;
        public LevelItem() levelItemArray;
        (Header("Animals Set"))
        public int lastUnlockedLevelAnimals = 0;
        public LevelItem() levelItemArrayAnimals;
        (Header("Architecture Set"))
        public int lastUnlockedLevelArch = 0;
        public LevelItem() levelItemArrayArch;
        (Header("Technology Set"))
        public int lastUnlockedLevelTech = 0;
        public LevelItem() levelItemArrayTech;
        (Header("Vehicles Set"))
        public int lastUnlockedLevelVehicles = 0;
        public LevelItem() levelItemArrayVehicles;
        (Header("Nature Set"))
        public int lastUnlockedLevelNature = 0;
        public LevelItem() levelItemArrayNature;

        (Header("Variables"))
        public int difficulty = 1;
        public int animalSet;
        public int architectureSet;
        public int technologySet;
        public int vehiclesSet;
        public int natureSet;
        public int allSets;
        public bool noAds = false;
    }

My SaveData function is pretty simple as it reads a string which is converted into JSON and saved

 public void SaveData()
        {
            string levelDataString = JsonUtility.ToJson(LevelSystemManager.Instance.LevelData);
            try
            {
                System.IO.File.WriteAllText(Application.persistentDataPath + "/LevelData.json", levelDataString);
                Debug.Log("Data Saved");

            }
            catch (System.Exception e)
            {
                Debug.Log("Error Saving Data:" + e);
                throw;
            }
        }

And my LoadData uses the same principles with the addition of checking if null and then setting each value one by one

 private void LoadData()
        {
            try
            {
                string levelDataString = System.IO.File.ReadAllText(Application.persistentDataPath + "/LevelData.json");
                LevelData levelData = JsonUtility.FromJson<LevelData>(levelDataString);
                if (levelData != null)
                {
                    // Primary Set //
                    LevelSystemManager.Instance.LevelData.levelItemArray = levelData.levelItemArray;
                    LevelSystemManager.Instance.LevelData.lastUnlockedLevel = levelData.lastUnlockedLevel;
                    // Animals Set//
                    LevelSystemManager.Instance.LevelData.levelItemArrayAnimals = levelData.levelItemArrayAnimals;
                    LevelSystemManager.Instance.LevelData.lastUnlockedLevelAnimals = levelData.lastUnlockedLevelAnimals;
                    // Architecture Set//
                    LevelSystemManager.Instance.LevelData.levelItemArrayArch = levelData.levelItemArrayArch;
                    LevelSystemManager.Instance.LevelData.lastUnlockedLevelArch = levelData.lastUnlockedLevelArch;
                    // Technology Set//
                    LevelSystemManager.Instance.LevelData.levelItemArrayTech = levelData.levelItemArrayTech;
                    LevelSystemManager.Instance.LevelData.lastUnlockedLevelTech = levelData.lastUnlockedLevelTech;
                    // Vehicles Set//
                    LevelSystemManager.Instance.LevelData.levelItemArrayVehicles = levelData.levelItemArrayVehicles;
                    LevelSystemManager.Instance.LevelData.lastUnlockedLevelVehicles = levelData.lastUnlockedLevelVehicles;
                    // nature Set//
                    LevelSystemManager.Instance.LevelData.levelItemArrayNature = levelData.levelItemArrayNature;
                    LevelSystemManager.Instance.LevelData.lastUnlockedLevelNature = levelData.lastUnlockedLevelNature;

                    // variables //
                    LevelSystemManager.Instance.LevelData.difficulty = levelData.difficulty;
                    LevelSystemManager.Instance.LevelData.animalSet = levelData.animalSet;
                    LevelSystemManager.Instance.LevelData.architectureSet = levelData.architectureSet;
                    LevelSystemManager.Instance.LevelData.technologySet = levelData.technologySet;
                    LevelSystemManager.Instance.LevelData.vehiclesSet = levelData.vehiclesSet;
                    LevelSystemManager.Instance.LevelData.natureSet = levelData.natureSet;
                    LevelSystemManager.Instance.LevelData.allSets = levelData.allSets;
                }
                    Debug.Log("Data Loaded");
            }
            catch (System.Exception e)
            {
                Debug.Log("Error Loading Data:" + e);
                throw;
            }
        }

What i would like is for someone to help me understand how to implement this into firebase. Reading the documentation i did try to initialize it and by following along i came across this part

private void writeNewUser(string userId, string name, string email) {
    User user = new User(name, email);
    string json = JsonUtility.ToJson(user);

    mDatabaseRef.Child("users").Child(userId).SetRawJsonValueAsync(json);
}

which i did try to replicate , unsuccessful obviously

string levelDataString = JsonUtility.ToJson(LevelSystemManager.Instance.LevelData);
reference.Child("users").Child(levelDataString).SetRawJsonValueAsync(levelDataString);

So i would be grateful for some hints or a tutorial on how to save and load each value. Thank you!

Carregar duas Collection do firebase no flutter

Boa noite pessoal, eu tenho o código abaixo.

return StreamBuilder(
  stream: _stream,
  builder: (context, snapshot1) {
    return StreamBuilder(
      stream: _stream2,
      builder: (context, snapshot2) {
        if (!snapshot2.hasData) return const Text('Loading...');
        if (!snapshot1.hasData) return const Text('Loading...');
        return ListView.builder(
          itemExtent: 550.0,
          itemCount: snapshot2.data.documents.length,
          itemBuilder: (BuildContext context, int data) {
            User user = User.fromDoc(snapshot2.data.documents(data));
            Post post = Post.fromDoc(snapshot1.data.documents(data));
            return buildbody(user, post, context);
          },
        );
      },
    );
  },
);

Porém não entendi como essa parte funciona.

User user = User.fromDoc(snapshot2.data.documents(data));
Post post = Post.fromDoc(snapshot1.data.documents(data));

android – No me aparece el listado en Firebase

Actualmente estoy probando a conectarme a una BD en tiempo real en Firebase, pero el problema está en que en mi tablet me aparece el listado de todos los productos, pero en cambio en la consola de Firebase no me lo está mostrando, a continuación adjunto captura de pantalla:

introducir la descripción de la imagen aquí

Mi código de la app Android es el siguiente:

public class MainActivity extends AppCompatActivity implements TextWatcher {
private static final String URL_broches = "http://192.168.43.3/WS/listar.php";
ArrayList<Broches> brochesList;
GridView gridView;
EditText editText;
Adapter adapter;
FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    gridView = (GridView)findViewById(R.id.gridview);
    editText = (EditText) findViewById(R.id.inputSearch);
    brochesList = new ArrayList<>();
    editText.addTextChangedListener(this);
    inicializarFirebase();
    listarDatos();
    loadBroches();
}

private void listarDatos() {
    databaseReference.child("Broches").addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot snapshot) {
            brochesList.clear();
            for(DataSnapshot objSnaptshot : snapshot.getChildren()){
                Broches b = objSnaptshot.getValue(Broches.class);
                brochesList.add(b);

                adapter = new Adapter(brochesList, MainActivity.this);
                gridView.setAdapter(adapter);
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError error) {

        }
    });
}

public void inicializarFirebase(){
    FirebaseApp.initializeApp(this);
    firebaseDatabase = FirebaseDatabase.getInstance();
    firebaseDatabase.setPersistenceEnabled(true);
    Log.d("prueba1", String.valueOf(firebaseDatabase));
    databaseReference = firebaseDatabase.getReference();
    Log.d("prueba2", String.valueOf(databaseReference));

}

private void loadBroches(){
    StringRequest stringRequest = new StringRequest(Request.Method.GET, URL_broches, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {

            Broches bro = null;
            try {
                JSONArray array = new JSONArray(response);
                for (int i = 0; i < array.length(); i++) {
                    JSONObject broche = array.getJSONObject(i);
                    bro = new Broches();
                    bro.setDescripcion(broche.getString("progennom"));
                    bro.setCodigo(broche.getString("progencod"));
                    bro.setPrecio(broche.getDouble("PreProPre1"));
                    bro.setImage(broche.getString("ImaAsoIma"));
                    //bro.setDato(broche.getString("ImaAsoIma"));
                    brochesList.add(bro);
                }
                adapter = new Adapter(brochesList, MainActivity.this);
                gridView.setAdapter(adapter);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_SHORT).show();
        }
    });

    Volley.newRequestQueue(this).add(stringRequest);
}

Cabe aclarar que hice Log de las variables firebaseDatabae y databaseReference de la siguiente manera:

Log.d("prueba1", String.valueOf(firebaseDatabase));
Log.d("prueba2", String.valueOf(databaseReference));

Y eso me devuelve lo que aparece a continuación:

introducir la descripción de la imagen aquí

¿Puede que esté haciendo algo mal en mi código? Aquí cabe aclarar que me aseguré de haber hecho las configuraciones correspondientes en Firebase

Google Data Studio – “(not set)” value when using Custom Dimension from Google Analytics in Firebase

I’m using Google Analytics in Firebase and I want to make a report in Google Data Studio. I created one custom dimension for an event but in Google Data Studio I only see “(not set)” value for this dimension.

I already tried:

  • Waiting 24h (I waited more than 3 days)
  • Register more users (now I sent data from 8 devices and I see 8 unique users in the analytics)

Here are two screenshots, the first one is from Custom Definitions page in Firebase Console and the second one is one chart from Google Data Studio.

Custom Definitions Page

Chart in Google data Studio

How to connect firebase firestore with my local firebase emulator suite?

For my local development i installed the firebase emulators through firebase cli.
Now i want my project to connect to the emulated firebase.

The connection to emulated Auth is already running fine.

I’m trying to use “useEmulator” on my firebase.firestore()
My code is basically from the Docs (https://firebase.google.com/docs/emulator-suite/connect_firestore#web)

const db = firebase.firestore()
const auth = firebase.auth()
if (location.hostname === "localhost") {
  console.log('LOCAL')
  auth.useEmulator("http://localhost:9099")
  db.useEmulator("localhost", 8080)
}

I get this error Uncaught TypeError: s.useEmulator is not a function
On this line: db.useEmulator(“localhost”, 8080)

What point did i miss? Thanks for help!