0
votes

I'm working on an assignment. I've to use Database provided by a provider 'hacker-news'. Also i've to use Firebase Authentication. I've setup a new project in my own account. Retrieving data from Hacker-news database works with below line. I'm able to fetch publicly accessible data with firebase child() APIs is

database = FirebaseDatabase.getInstance("https://hacker-news.firebaseio.com/");

But when i implemented Firebase Authentication and once user logs in it is giving error

Provided authentication credentials are invalid. This usually indicates your FirebaseApp instance was not initialized correctly. Make sure your google-services.json file has the correct firebase_url and api_key

I've spent lot of time on internet and found a link to implement multiple databases in single project - Working with multiple Firebase projects in an Android app by Google

This works only if you are the owner of those Databases. Is there anyway i can access Hacker-news Database using SDK not REST-API?

1

1 Answers

0
votes
        FirebaseOptions options = new FirebaseOptions.Builder()
                        .setDatabaseUrl(getResources().getString(R.string.dbURL))
                        .setApiKey(getResources().getString(R.string.api))
                        .setApplicationId(getResources().getString(R.string.appID))
                        .setProjectId(getResources().getString(R.string.projectId))
                        .setStorageBucket(getResources().getString(R.string.storageBucket)).build();
//set all variable above as your need

        boolean hasBeenInitialized=false;
                List<FirebaseApp> fireBaseApps = FirebaseApp.getApps(getApplicationContext());
                for(FirebaseApp app : fireBaseApps){
                    if(app.getName().equals("any_name")){
                        hasBeenInitialized=true;

                    }
                }

                if (!hasBeenInitialized) {
                    smaTeacher = FirebaseApp.initializeApp(this, options, "any_name");

                }
    database=FirebaseDatabase.getInstance(FirebaseApp.getInstance("any_name"));