0

my android application is using external financial API. I want store these JSON data in my firebase DB. so I want my customer get data from my firebase server. is there easy way?

For example.. https://www.worldtradingdata.com/api/v1/stock?symbol=AAPL

{

"symbols_requested":1,
"symbols_returned":1,
"data":[
    {
        "symbol":"AAPL",
        "name":"Apple\r\nInc.",
        "currency":"USD",
        "price":"153.07",
        "price_open":"150.27",
        "day_high":"153.39",
        "day_low":"150.05",
        "52_week_high":"233.47",
        "52_week_low":"142.00",
        "day_change":"3.07",
        "change_pct":"2.05",
        "close_yesterday":"150.00",
        "market_cap":"723990979852",
        "volume":"7034",
        "volume_avg":"46777427",
        "shares":"4729803000",
        "stock_exchange_long":"NASDAQ\r\nStock\r\n Exchange",
        "stock_exchange_short":"NASDAQ",
        "timezone":"EST",
        "timezone_name":"America/New_York",
        "gmt_offset":"-18000",
        "last_trade_time":"2019-01-15\r\n 16:00:01"
    }
]

}

then I want store these JSON data in my firebase server.

호진차
  • 13
  • 5
  • 1
    just add some code so we can help you better – Gregorio Palamà Jan 16 '19 at 11:29
  • thanks. but there is no code related it. i just want to know way – 호진차 Jan 16 '19 at 12:03
  • Yes, there's an easy way. Write an app that takes the JSON data and converts it into an appropriate Firebase structure. You structure will be determined by what you want to get out of Firebase - queries? Events? What's the relationship between data? Once you're attempted to write said app, when you get stuck, post your code here so we can take a look.Please take a moment and review [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Jay Jan 16 '19 at 19:05

2 Answers2

1

There is no direct way of doing it.You will have to parse data using Retrofit or volley and then will have to upload on Firebase. PS. Why do you want to send data to firebase while you already have in .json format.

Firebase aslo stores data in json format

Rajat Mittal
  • 413
  • 5
  • 19
  • thank you for reply. using api spend many money. so i want put data into my server then i serve information. – 호진차 Jan 16 '19 at 12:00
  • Process of migrating data from json to firebase then showing it on application is long. it may affect the speed(performance) of your application also. – Rajat Mittal Jan 16 '19 at 12:05
  • yes. i know. so i made another program that manage data for get data from external api url. i need to get data from api only one time in day. the data manager program operate one time and then many customer use data from my firebase server – 호진차 Jan 16 '19 at 12:17
  • There is no shortcut of this as far as i know. – Rajat Mittal Jan 16 '19 at 12:20
  • ok. i see. as you said, i would have to write code to convert. thank you for your reply anyway – 호진차 Jan 16 '19 at 12:25
  • Cheers! Hope you will maintain it. – Rajat Mittal Jan 16 '19 at 12:27
0

If you want to post the JSON data to Firebase from the Android app, you can either parse the JSON data in the Android code, and then write it using the Firebase SDK, or you can send the JSON string directly to Firebase's REST API.

Alternatively you can implement a Cloud Function, which is code that runs on Google's servers, and call the 3rd party API from there. In steps this Cloud function:

  1. Calls the 3rd party API to get the data
  2. Writes that data to the Firebase database, that your clients then listen to

  3. You then trigger this function periodically as described here: Cloud Functions for Firebase trigger on time?. I typically use cron-job.org for this.

Note that your Firebase project will need to be on a paid plan to be able to call 3rd party APIs.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • thank you. I will try it in the clould fuction way you said – 호진차 Jan 16 '19 at 18:56
  • it's very useful answer for me. but could you tell me if these way (cloud function) can JSON data (from 3rd party API) put into firebase db directly? not parse the JSON data. and what to do. – 호진차 Jan 16 '19 at 21:30
  • In Cloud Functions you can either parse the JSON sting with `JSON.parse(...)`, or pass the string to the REST API. – Frank van Puffelen Jan 17 '19 at 02:17