Skip to content Skip to sidebar Skip to footer

Storing Api Keys On The Realtime Database (firebase)

My android app requires using the Google Place Search API but since it's not available for android, I'll have to call the Web API. I've considered using Cloud Functions but that's

Solution 1:

Storing the key in the database still requires that users can access it. So while it's one level more effort to retrieve, malicious users will still be able to retrieve it.

A server-side key should simply not be used in client-side code.

Solution 2:

Google Places APIs are available for android.

Sample Code

publicvoidfindPlace(View view) {
try {
    Intentintent=newPlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                    .setFilter(typeFilter)
                    .build(this);
        startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
    } catch (GooglePlayServicesRepairableException e) {
        // TODO: Handle the error.
    } catch (GooglePlayServicesNotAvailableException e) {
        // TODO: Handle the error.
    }
}

// A place has been received; use requestCode to track the request.@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Placeplace= PlaceAutocomplete.getPlace(this, data);
            Log.i(TAG, "Place: " + place.getName());
        } elseif (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Statusstatus= PlaceAutocomplete.getStatus(this, data);
            // TODO: Handle the error.
            Log.i(TAG, status.getStatusMessage());

        } elseif (resultCode == RESULT_CANCELED) {
            // The user canceled the operation.
        }
    }
}

Complete tutorial is available here.

Post a Comment for "Storing Api Keys On The Realtime Database (firebase)"