Firebase remote config alternatives - firebase

Are there some alternatives to Firebase Remote Config?
I need to deliver an App for chinese market and I'm not sure that it will work

I've solved with Parse https://parseplatform.org/
there's also a baas implementation provided by https://www.back4app.com/ with a free tier

Yeah, you can use Huawei Remote Configuration, it mostly matches Firebase for API style.
Sign up for the Huawei console https://developer.huawei.com/consumer/en/agconnect/remote-configuration/
Add the dependencies:
implementation 'com.huawei.agconnect:agconnect-core:1.5.2.300'
implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.5.2.300'
implementation 'com.huawei.hms:hianalytics:6.0.0.300'
Fetch the same as Firebase Remote Config:
config = AGConnectConfig.getInstance()
config.fetch(0) // a value of 0 here is for DEBUGGING ONLY, delete for prod (giving a 12 hour refresh period)
.addOnSuccessListener {
config.apply(it)
Log.d(TAG, "Applied")
//update based on RemoteConfig
}
Reference: https://blog.blundellapps.co.uk/remote-configuration-using-appgallery-connect/

Related

Firebase Admin SDK Not Reading, Writing, or Throwing Errors (Node.js)

This question was previously closed, telling me to "update the question so it focuses on one problem only;" I don't know what the problem is, and if I did, I wouldn't be posting this question. Regardless, I'll make some clarifications here:
I was previously using just the normal Firebase module (the one imported using "npm i firebase"); everything worked perfectly before. The issue has to do with the authentication (as far as I am aware) with the Firebase Admin SDK. I don't understand how I'm supposed to send this to the Heroku build without revealing the service account key JSON file on my GitHub.
As for the GOOGLE_APPLICATION_CREDENTIALS path, is there a way where I don't have to set it every session? The Heroku app restarts once a day, and I would need to somehow automate this entry process (or skip it entirely). That's the way I currently understand it. Here's a quote from a previous answer:
When I set the GOOGLE_APPLICATION_CREDENTIALS path, doesn't this only set it on my local machine?
Environment variables only work on the individual machine and process where they have been set. If you want it set on another machine and process, you will have to arrange for that separately. According to the documentation:
Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.
My main question here is as follows: "I implemented the Firebase Admin SDK incorrectly. How do I do it the right way?"
Even just posting a link to guides that would help would be appreciated (although I understand this is typically discouraged as links sometimes break).
Original:
Note: this is my first time using the Firebase Admin SDK, so I'm really not sure what I'm doing (although I have used Firebase quite a bit).
Recently, I decided I would go back to one of my older Discord bots and actually authenticate its requests to Firebase properly (I hadn't done this previously as I've never authenticated from a server before and didn't think it was possible). I discovered the Firebase Admin SDK, which sounded perfect for my needs (the bot is being hosted on Heroku, for the record).
I found this guide: https://firebase.google.com/docs/admin/setup, but there's a few things I can't wrap my head around (note that these are purely rhetorical, you don't need to answer them in your answer; I'm just providing them so you can understand my thought process):
When I set the GOOGLE_APPLICATION_CREDENTIALS path, doesn't this only set it on my local machine? I could also try running the export command on the server (using "heroku run" in the CLI), but then the path would be pointing to a file that doesn't exist on the server (since the service account key JSON file is on my local machine). Do I need to set an environment variable in Heroku or something?
How does "admin.credential.applicationDefault()" know how to get the credentials?
I can't find any other guides that make sense.
The way I currently have it setup must be wrong, since reads and writes fail silently.
Firebase setup code:
// Setup Firebase:
const admin = require('firebase-admin');
// Initialize Firebase:
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: "https://<APP>.firebaseio.com" // I removed the actual <APP> name to ask this question
});
let database = admin.database();
Things like database.ref("test").set("Hello World!"); don't change the data in the database, and no errors are thrown (I've also tried attaching a .then and a .catch to the end of this; still nothing). This was working before I switched over to the Firebase Admin SDK (I was just using the "firebase" module previously, rather than the "firebase-admin" module that I'm now using). The same goes for reading data.
Any help would be appreciated.
Here was my problem:
I was sending res.status(200) outside of the async firebase call, killing the request before firebase had a chance to finish. Somehow localhost allows this to work properly but when its hosted things go sideways.
so I had this
fireabse.database().ref('parent/foo').set('bar');
res.status(200)
I needed this:
firebase.database().ref('parent/foo').set('bar').then(() => {
res.status(200);
});

How to get "Apps Instance Id" in Flutter

i want to setup firebase inapp messaging on my flutter apps.
first, it need FirebaseInstanceId as explained here, so i can test send message to my device.
However the document does not tell more detail how to get it on Android, especially on flutter.
any idea ?
Note : someone has claimed that he can use inapp-messaging in flutter, please see here
Thank you in Advance...
The Firebase Instance ID can be fetched using -instanceIDWithHandler on iOS or getInstanceId on Android.
At the time of writing, I am not aware of a standalone plugin that does this, meaning that you have two options:
Write your own plugin that wraps the native implementations of those methods
Use the firebase_messaging Flutter plugin that happens to expose the Instance ID via its getToken() method
If you go the firebase_messaging route (mind you, it means you're adding another dependency), you can do something like this:
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
and then, somewhere in your code:
var token = await _firebaseMessaging.getToken();
print("Instance ID: $token");
Update
When you call get token, you get something in the following format: NNNNNNN:MMMMMMMMMMMMMMMMMM. Take only the first part before the colon (NNNNNNNN) - this is the instance ID you need to test your In-App Messaging campaign.
You can run this in your terminal.
adb logcat | grep 'InAppMessaging'
02-26 23:47:44.835 28379 28379 I FIAM.Headless: Starting
InAppMessaging runtime with Installation ID dTEmOkEwRzC_xiO8YNPXs0
To retrieve the FirebaseInstanceId you need to implement the Firebase In-App messaging SDK and make sure your app connects to Firebase.
Once the app is connected to Firebase it will add the FirebaseInstanceId to the Android log once the App is run.
In the article you linked Google explains that you can find the FirebaseInstanceId by looking in the log for the string I/FIAM.Headless: Starting InAppMessaging runtime with Instance ID <YOUR_APP_ID>.
If you are using Android Studio you should be able to use the logcat window to browse the logs of the device (while debugging the App). The logcat window will also allow you to search and filter the logs so it should be relative easy to find the mentioned string.
So in short (in Android Studio):
Implement the Firebase In-App messaging SDK in your App;
Start debugging the App (preferably on a real Android device);
While debugging open the Logcat window;
Search the logs for the string I/FIAM.Headless: Starting InAppMessaging runtime with Instance ID;
The FirebaseInstanceId should be listed directly after the string.
Using flutterfire_installations, you can get:
Installation ID:
String id = await FirebaseAppInstallations.instance.getId();
Authentication token:
String token = await FirebaseAppInstallations.instance.getToken();

Can Firebase RemoteConfig be accessed from cloud functions

I'm using Firebase as a simple game-server and have some settings that are relevant for both client and backend and would like to keep them in RemoteConfig for consistency, but not sure if I can access it from my cloud functions in a simple way (I don't consider going through the REST interface a "simple" way)
As far as I can tell there is no mention of it in the docs, so I guess it's not possible, but does anyone know for sure?
firebaser here
There is a public REST API that allows you to read and set Firebase Remote Config conditions. This API requires that you have full administrative access to the Firebase project, so must only be used on a trusted environment (such as your development machine, a server you control or Cloud Functions).
There is no public API to get Firebase Remote Config settings from a client environment at the moment. Sorry I don't have better news.
This is probably only included in newer versions of firebase (8th or 9th and above if I'm not mistaken).
// We first need to import remoteConfig function.
import { remoteConfig } from firebase-admin
// Then in your cloud function we use it to fetch our remote config values.
const remoteConfigTemplate = await remoteConfig().getTemplate().catch(e => {
// Your error handling if fetching fails...
}
// Next it is just matter of extracting the values, which is kinda convoluted,
// let's say you want to extract `game_version` field from remote config:
const gameVersion = remoteConfigTemplate.parameters.game_version.defaultValue.value
So parameters are always followed by the name of the field that you defined in Firebase console's remote config, in this example game_version.
It's a mouthful (or typeful) but that's how you get it.
Also note that if value is stored as JSON string, you will need to parse it before usage, commonly: JSON.parse(gameVersion).
Similar process is outlined in Firebase docs.

How to upload files from JAVA server to Firebase Storage by any means necessary [duplicate]

How can I integrate Firebase with a Java desktop application?
Is there a .jar file I could download?
I've seen plain Java docs on the old Firebase version but I'm unable to find any documentation on the latest version of Firebase.
My IDE is Netbeans.
Thanks.
According to the documentation website Firebase will not work just like that, it's an application designed to run only on 3 platforms, namely:
Android
iOS
Web
You can try and use the maven repository for the integration purpose, with any build script. I'm not exactly sure what you expect to do.
For Firebase Storage on the server, I recommend using gcloud-java:
// Authenticate using a service account
Storage storage = StorageOptions.builder()
.authCredentials(AuthCredentials.createForJson(new FileInputStream("/path/to/my/key.json"))
.build()
.service();
// Create blob
BlobId blobId = BlobId.of("bucket", "blob_name");
// Add metadata to the blob
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
// Upload blob to GCS (same as Firebase Storage)
Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
You can use firebase-server-sdk-3.0.1.jar (current version)
In Netbeans I would recommend to create Maven project and use artifact: GroupId - com.google.firebase, ArtifactId: firebase-server-sdk.
I works perfectly for me.
You can find some documentation here.
To initialize SDK just follow documentation: add service account (I use Owner role, I haven't tried weaker roles), download private key, and use this snippet:
FirebaseOptions options = new FirebaseOptions.Builder()
.setServiceAccount(new FileInputStream("path/to/downloaded private key.json"))
.setDatabaseUrl("https://your database name.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);

NotificationHub Push Notification returns : The Token obtained from the Token Provider is wrong

I have Wp8.1 Silverlight app that receives push notification (WNS) from Mobileservice (the old azure service).
I therefore wanted to update to the new service because of the new features. I have now created/upgraded a new server to use App Service - Mobile App. And tested push notification with the sample app from azure (everything works).
Going back to my app WP8.1 -> Adding the new package Microsoft.Azure.Mobile.Client through NuGet (2.0.1), there is the issue that the Microsoft.WindowsAzure.Mobile.Ext does not contain the 'GetPush' extension. It seems like it is missing it? looking to the WP8 version, it only registers to MPNS, and I need WNS. So I do not know if any other assembly could be used.
Can I add another assembly reference?
Update
The following code lets me register the device on the server, and I can see the device register correctly. where the channelUri and the installationInformation are retrieved by the client and send to the server.
Installation ins = new Installation();
ins.Platform = NotificationPlatform.Wns;
ins.PushChannel = uTagAndChan.ChannelUri;
ins.Tags = uTagAndChan.Tags;
ins.InstallationId = uTagAndChan.installationInformation;
await hubClient.CreateOrUpdateInstallationAsync(ins);
Sending a test toast-notification to the registered tags, results in the following error :
The Token obtained from the Token Provider is wrong
Searching on this issue I found Windows Store App Push Notifications via Azure Service Bus. Which the proposed solution says to register to the notification hub directly from the app, I would rather not have the app to have directly access to the hub. But is this the only way? (mind you the answer was not accepted, but I will try it all though it is not a desired solution)
Update
Registering for notifications via client (WP8.1 Silverligt), makes a registration to MPNS, which I do not want.
The snippet on the server registers a WNS, the two registrations can be seen here:
The URI retrieval is done using
var channel = await Windows.Networking.PushNotifications.PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
which in the description states it returns a WNS. This seems to infer that the registration I am doing on the server (code snippet in the top) is correct and the registration on the client is faulty.
But the registration on the image seems wrong. Shouldn't the PNS Identifier be different for the two registrations? also expiration date seems wrong ?
How to mend this since the GetPush() (which was available in the sample registered the client correctly for notifications) does not exist in the NuGet package?
Update
I read one place that deleting and recreating the NotificationHub could help. I will try this today. Even IF it works, it would be more desirable to have the solution, and to know if the registrations are done correctly?
Temporary solution:
Deltede, recreated, inserted Package SID and Secret. And it works again (strange)!
Still interested in the underlying issue!
Deleted and recreated the service, setting all the same settings made it work again.
I had same issue with my UWP. But in my case I had issue with self signed certificate.
When I set the AppxPackageSigningEnabled property to True (in .csproj) then notifications stopped working and I got "The token obtained from the Token Provider is wrong" (Test send from Azure Portal).
The certificate must have same issuer as Publisher in Identity element in .appxmanifest file.

Resources