Firebase Remote Config
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Elabora le modifiche ai valori di Firebase Remote Config.
Per saperne di più
Per la documentazione dettagliata che include questo esempio di codice, vedi quanto segue:
Esempio di codice
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis document provides code samples for processing changes to Firebase Remote Config values across multiple languages.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code samples demonstrate how to log essential details about a Remote Config update, including the update type, origin, and version number.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Cloud Run functions requires setting up Application Default Credentials, as detailed in the "Set up authentication for a local development environment" document.\u003c/p\u003e\n"],["\u003cp\u003eThe document also contains a link to other code samples using the "Google Cloud Sample browser".\u003c/p\u003e\n"]]],[],null,["# Firebase remote config\n\nProcess changes to Firebase remote config values.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Firebase Remote Config Triggers](/functions/1stgendocs/calling/firebase-remote-config)\n\nCode sample\n-----------\n\n### C#\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n using CloudNative.CloudEvents;\n using Google.Cloud.Functions.Framework;\n using Google.Events.Protobuf.Firebase.RemoteConfig.V1;\n using Microsoft.Extensions.Logging;\n using System.Threading;\n using System.Threading.Tasks;\n\n namespace FirebaseRemoteConfig;\n\n public class Function : ICloudEventFunction\u003cRemoteConfigEventData\u003e\n {\n private readonly ILogger _logger;\n\n public Function(ILogger\u003cFunction\u003e logger) =\u003e\n _logger = logger;\n\n public Task HandleAsync(CloudEvent cloudEvent, RemoteConfigEventData data, CancellationToken cancellationToken)\n {\n _logger.LogInformation(\"Update type: {origin}\", data.UpdateType);\n _logger.LogInformation(\"Update origin: {origin}\", data.UpdateOrigin);\n _logger.LogInformation(\"Version number: {version}\", data.VersionNumber);\n\n // In this example, we don't need to perform any asynchronous operations, so the\n // method doesn't need to be declared async.\n return Task.CompletedTask;\n }\n }\n\n### Go\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n // Package helloworld provides a set of Cloud Functions samples.\n package helloworld\n\n import (\n \t\"context\"\n \t\"log\"\n )\n\n // A RemoteConfigEvent is an event triggered by Firebase Remote Config.\n type RemoteConfigEvent struct {\n \tUpdateOrigin string `json:\"updateOrigin\"`\n \tUpdateType string `json:\"updateType\"`\n \tUpdateUser struct {\n \t\tEmail string `json:\"email\"`\n \t\tImageURL string `json:\"imageUrl\"`\n \t\tName string `json:\"name\"`\n \t} `json:\"updateUser\"`\n \tVersionNumber string `json:\"versionNumber\"`\n }\n\n // HelloRemoteConfig handles Firebase Remote Config events.\n func HelloRemoteConfig(ctx context.Context, e RemoteConfigEvent) error {\n \tlog.Printf(\"Update type: %v\", e.UpdateType)\n \tlog.Printf(\"Origin: %v\", e.UpdateOrigin)\n \tlog.Printf(\"Version: %v\", e.VersionNumber)\n \treturn nil\n }\n\n### Java\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import com.google.cloud.functions.Context;\n import com.google.cloud.functions.RawBackgroundFunction;\n import com.google.gson.Gson;\n import com.google.gson.JsonObject;\n import java.util.logging.Logger;\n\n public class FirebaseRemoteConfig implements RawBackgroundFunction {\n private static final Logger logger = Logger.getLogger(FirebaseRemoteConfig.class.getName());\n\n // Use GSON (https://github.com/google/gson) to parse JSON content.\n private static final Gson gson = new Gson();\n\n @Override\n public void accept(String json, Context context) {\n JsonObject body = gson.fromJson(json, JsonObject.class);\n\n if (body != null) {\n if (body.has(\"updateType\")) {\n logger.info(\"Update type: \" + body.get(\"updateType\").getAsString());\n }\n if (body.has(\"updateOrigin\")) {\n logger.info(\"Origin: \" + body.get(\"updateOrigin\").getAsString());\n }\n if (body.has(\"versionNumber\")) {\n logger.info(\"Version: \" + body.get(\"versionNumber\").getAsString());\n }\n }\n }\n }\n\n### Node.js\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n /**\n * Background Function triggered by a change to a Firebase Remote Config value.\n *\n * @param {object} event The Cloud Functions event.\n */\n exports.helloRemoteConfig = event =\u003e {\n console.log(`Update type: ${event.updateType}`);\n console.log(`Origin: ${event.updateOrigin}`);\n console.log(`Version: ${event.versionNumber}`);\n };\n\n### PHP\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n use Google\\CloudFunctions\\CloudEvent;\n\n function firebaseRemoteConfig(CloudEvent $cloudevent)\n {\n $log = fopen(getenv('LOGGER_OUTPUT') ?: 'php://stderr', 'wb');\n\n $data = $cloudevent-\u003egetData();\n\n fwrite($log, 'Update type: ' . $data['updateType'] . PHP_EOL);\n fwrite($log, 'Origin: ' . $data['updateOrigin'] . PHP_EOL);\n fwrite($log, 'Version: ' . $data['versionNumber'] . PHP_EOL);\n }\n\n### Python\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n def hello_remote_config(data, context):\n \"\"\"Triggered by a change to a Firebase Remote Config value.\n Args:\n data (dict): The event payload.\n context (google.cloud.functions.Context): Metadata for the event.\n \"\"\"\n print(f'Update type: {data[\"updateType\"]}')\n print(f'Origin: {data[\"updateOrigin\"]}')\n print(f'Version: {data[\"versionNumber\"]}')\n\n### Ruby\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n require \"functions_framework\"\n\n # Triggered by a change to a Firebase Remote Config value\n FunctionsFramework.cloud_event \"hello_remote_config\" do |event|\n # Event-triggered Ruby functions receive a CloudEvents::Event::V1 object.\n # See https://cloudevents.github.io/sdk-ruby/latest/CloudEvents/Event/V1.html\n # The Firebase event payload can be obtained from the event data.\n payload = event.data\n\n logger.info \"Update type: #{payload['updateType']}\"\n logger.info \"Origin: #{payload['updateOrigin']}\"\n logger.info \"Version: #{payload['versionNumber']}\"\n end\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=functions)."]]