#android #firebase #firebase-realtime-database
#Android #firebase #firebase-realtime-database
Вопрос:
Я создаю приложение для обновления цен в реальном времени на различные доступные онлайн-продукты. Но я не могу отправить данные в базу данных реального времени. Я за то, чтобы узнать, как ссылаться на базу данных в реальном времени.
const functions = require('firebase-functions');
var admin = require("firebase-admin");
const request = require('request');
const cheerio = require('cheerio');
// URL
const URL = "https://www.flipkart.com/search?q=mobiles";
admin.initializeApp({
"serviceAccount": "./InfoApp-2b1936e80782.json",
"databaseURL": "https://infoapp-234ff.firebaseio.com"
});
var ref = admin.database().ref("hello"); //('data').child(data).child('specs');
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
exports.helloWorld = functions.https.onRequest((request, response) => {
let $ = cheerio.load(body);
$('div._1HmYoV > div.col-10-12>div.bhgxx2>div._3O0U0u').each(function(index){
const data = $(this).find('div._1UoZlX>a').attr('href');
const name = $(this).find('div._1-2Iqu>div.col-7-12>div._3wU53n').text();
console.log(data);
var a = ref.push();
a.set({
author: "gracehop",
title: "Announcing COBOL, a New Programming Language"
});
});
response.send("activity !");
});
`
Ответ №1:
Функция push не возвращает ссылку. Вы можете заменить это:
var a = ref.push();
a.set({
author: "gracehop",
title: "Announcing COBOL, a New Programming Language"
});
с помощью:
ref.push({
author: "gracehop",
title: "Announcing COBOL, a New Programming Language"
});