【问题标题】:I want to update programmatically the parameter from the Firebase Remote Config我想以编程方式更新 Firebase 远程配置中的参数
【发布时间】:2018-06-04 14:27:17
【问题描述】:

这是我的代码:

  final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance();
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
            .setDeveloperModeEnabled(BuildConfig.DEBUG)
            .build();
    config.setConfigSettings(configSettings);
    config.fetch(0).addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                // After config data is successfully fetched, it must be activated before newly fetched
                // values are returned.
                config.activateFetched();
                    final String playStoreVersionCode = FirebaseRemoteConfig.getInstance().getString(
                            "android_latest_version_code");
            } else {
                Utils.appendLog("playStoreVersionCode Error fetching latest params ", "E", Constants.TIMELINE);
            }
        }
    });

现在我想增加我的参数,我看到从 3 月开始有一个 REST API 来更新参数:

https://firebase.google.com/docs/remote-config/api-overview https://firebase.google.com/docs/remote-config/use-config-rest

但我不太了解教程。 为什么我需要使用 curl?这真的像在 use-config-rest 链接中那样有必要吗?

curl --compressed -D headers -H "Authorization: Bearer token" -X GET https://firebaseremoteconfig.googleapis.com/v1/projects/my-project-id/remoteConfig -o filename

快速入门只是展示了一个关于如何获取数据的示例,而不是更改它: https://github.com/firebase/quickstart-android/blob/master/config/app/src/main/java/com/google/samples/quickstart/config/MainActivity.java

【问题讨论】:

    标签: android rest firebase firebase-remote-config


    【解决方案1】:

    远程配置参数并不意味着要从客户端代码中更改。它们仅用于在客户端上阅读。如果您想以编程方式进行更改,则应该从您控制的服务器中执行此操作。

    如果您想在应用中读取/写入一些持久值,请不要使用远程配置。请改用实时数据库或 Firestore。

    在文档中显示 curl 命令的原因是为了说明如何使用许多人熟悉的命令发出 HTTP 请求。只要遵循规范,您就可以以任何方式发出 HTTP 请求。

    【讨论】:

    • 所以如果我理解正确的话。无法从客户端代码端更改远程配置。仅来自服务器。谢谢。然后我会调查 Firestore
    • 我不会说客户端没有办法做到这一点。它只是不打算那样工作。如果您想完成这项工作,则必须将项目管理员凭据包含到您的应用程序中,这是一个巨大的安全漏洞。远程配置参数仅供客户端使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 2011-03-16
    相关资源
    最近更新 更多