用于远程配置的 Firebase Rest api

Firebase Rest api for remote config

正在尝试寻找服务器到服务器(最好在 python 中), 连接 Firebase 远程配置。

操作:查看和编辑。

发现 this 个有用的 pip,

它包含身份验证、数据库和存储,但不包含远程配置。

我可以将我自己的添加到 pip,但我没有找到任何记录其余部分 api 到 Remote Config

更新 (2018-03-13):正如 Rosário 指出的那样,现在有一个 REST API 允许您阅读和编辑配置。

Web 客户端仍然没有 API 与 iOS 和 Android 客户端类似。

我之前的回答在首屏下方。


此时没有 public REST API 连接到 Firebase 远程配置。

另见:

Firebase 现在提供 Remote Config REST API!

要使用此 API,您必须先在 Google APIs Console 上启用它。 Select 您的项目,然后单击 "Enable" 按钮。

然后您需要一个访问令牌来授权 API 请求。您可以通过 3 个步骤获得令牌:

  1. 在 Firebase 控制台中,打开 设置 > Service Accounts
  2. 单击生成新私钥,然后单击生成密钥
  3. 安全存储包含密钥
  4. 的JSON文件

使用 Google API Client Library:

在您的服务器上检索令牌
def _get_access_token():
  """Retrieve a valid access token that can be used to authorize requests.

  :return: Access token.
  """

   var SCOPES = [
   "https://www.googleapis.com/auth/firebase.remoteconfig"
 ];

  credentials = ServiceAccountCredentials.from_json_keyfile_name(
      'service-account.json', SCOPES)
  access_token_info = credentials.get_access_token()
  return access_token_info.access_token

查看当前配置

您现在可以使用 API 查看当前的远程配置设置。您可以使用以下命令执行此操作:

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

只需将 my-project-id 替换为您的 Firebase 项目的 ID。您当前的远程配置设置将以 JSON 格式返回:

{
  "parameters": [{
    "key": "someKey",
    "value_options": [{
      "value": "Some value here"
    }]
   }, {
    "key": "otherKey",
    "value_options": [{
      "value": "someOtherValueHere"
    }]
  }]
}

编辑当前配置

获得 JSON 文件后,您可以对其进行编辑以更改配置,然后使用以下命令将其 re-send 发送至 Firebase:

curl --compressed -i -H "Content-Type: application/json; UTF8" -H "If-Match: last-returned-etag" -H "Authorization: Bearer token" -X PUT https://firebaseremoteconfig.googleapis.com/v1/projects/my-project-id/remoteConfig -d @filename.json

(再次将 my-project-id 替换为您当前的 Firebase 项目 ID)

好消息!现在有 REST API 可供您与远程配置服务通信。

您可以使用它来创建您自己的自定义 front-ends 来管理您的远程配置值,从其他地方导入远程配置值,或者添加支持以动态更改您的远程配置值,例如 server-to-server 沟通。试试吧!