Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Déclencheurs Firebase Remote Config
Cloud Run Functions peut être déclenché en réponse aux modifications de Firebase Remote Config dans le même projet Google Cloud contenant la fonction. Vous pouvez ainsi modifier le comportement et l'apparence de votre application sans publier de mise à jour.
Types d'événement
Firebase Remote Config peut déclencher des fonctions en réponse à l'événement remoteconfig.update.
Type d'événement
Déclencheur
remoteconfig.update
Déclenché lorsque le modèle Remote Config est mis à jour.
Structure de l'événement
Les données d'événement sont fournies en tant qu'objet remoteConfig transformé.
/** * Background Function triggered by a change to a Firebase Remote Config value. * * @param {object} event The Cloud Functions event. */exports.helloRemoteConfig=event=>{console.log(`Update type: ${event.updateType}`);console.log(`Origin: ${event.updateOrigin}`);console.log(`Version: ${event.versionNumber}`);};
Python
defhello_remote_config(data,context):"""Triggered by a change to a Firebase Remote Config value. Args: data (dict): The event payload. context (google.cloud.functions.Context): Metadata for the event. """print(f'Update type: {data["updateType"]}')print(f'Origin: {data["updateOrigin"]}')print(f'Version: {data["versionNumber"]}')
Go
// Package helloworld provides a set of Cloud Functions samples.packagehelloworldimport("context""log")// A RemoteConfigEvent is an event triggered by Firebase Remote Config.typeRemoteConfigEventstruct{UpdateOriginstring`json:"updateOrigin"`UpdateTypestring`json:"updateType"`UpdateUserstruct{Emailstring`json:"email"`ImageURLstring`json:"imageUrl"`Namestring`json:"name"`}`json:"updateUser"`VersionNumberstring`json:"versionNumber"`}// HelloRemoteConfig handles Firebase Remote Config events.funcHelloRemoteConfig(ctxcontext.Context,eRemoteConfigEvent)error{log.Printf("Update type: %v",e.UpdateType)log.Printf("Origin: %v",e.UpdateOrigin)log.Printf("Version: %v",e.VersionNumber)returnnil}
Java
importcom.google.cloud.functions.Context;importcom.google.cloud.functions.RawBackgroundFunction;importcom.google.gson.Gson;importcom.google.gson.JsonObject;importjava.util.logging.Logger;publicclassFirebaseRemoteConfigimplementsRawBackgroundFunction{privatestaticfinalLoggerlogger=Logger.getLogger(FirebaseRemoteConfig.class.getName());// Use GSON (https://github.com/google/gson) to parse JSON content.privatestaticfinalGsongson=newGson();@Overridepublicvoidaccept(Stringjson,Contextcontext){JsonObjectbody=gson.fromJson(json,JsonObject.class);if(body!=null){if(body.has("updateType")){logger.info("Update type: "+body.get("updateType").getAsString());}if(body.has("updateOrigin")){logger.info("Origin: "+body.get("updateOrigin").getAsString());}if(body.has("versionNumber")){logger.info("Version: "+body.get("versionNumber").getAsString());}}}}
C#
usingCloudNative.CloudEvents;usingGoogle.Cloud.Functions.Framework;usingGoogle.Events.Protobuf.Firebase.RemoteConfig.V1;usingMicrosoft.Extensions.Logging;usingSystem.Threading;usingSystem.Threading.Tasks;namespaceFirebaseRemoteConfig;publicclassFunction:ICloudEventFunction<RemoteConfigEventData>{privatereadonlyILogger_logger;publicFunction(ILogger<Function>logger)=>
_logger=logger;publicTaskHandleAsync(CloudEventcloudEvent,RemoteConfigEventDatadata,CancellationTokencancellationToken){_logger.LogInformation("Update type: {origin}",data.UpdateType);_logger.LogInformation("Update origin: {origin}",data.UpdateOrigin);_logger.LogInformation("Version number: {version}",data.VersionNumber);// In this example, we don't need to perform any asynchronous operations, so the// method doesn't need to be declared async.returnTask.CompletedTask;}}
Ruby
require"functions_framework"# Triggered by a change to a Firebase Remote Config valueFunctionsFramework.cloud_event"hello_remote_config"do|event|# Event-triggered Ruby functions receive a CloudEvents::Event::V1 object.# See https://cloudevents.github.io/sdk-ruby/latest/CloudEvents/Event/V1.html# The Firebase event payload can be obtained from the event data.payload=event.datalogger.info"Update type: #{payload['updateType']}"logger.info"Origin: #{payload['updateOrigin']}"logger.info"Version: #{payload['versionNumber']}"end
Nom enregistré de la fonction Cloud Run que vous déployez.
Il peut s'agir du nom d'une fonction dans votre code source ou d'une chaîne arbitraire. Si FUNCTION_NAME est une chaîne arbitraire, vous devez alors inclure l'option --entry-point.
--entry-point ENTRY_POINT
Nom d'une fonction ou d'une classe dans votre code source. Ce paramètre est facultatif, sauf si vous n'avez pas utilisé FUNCTION_NAME pour spécifier quelle fonction de votre code source exécuter lors du déploiement. Dans ce cas, vous devez utiliser --entry-point pour fournir le nom de la fonction exécutable.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/01/31 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/01/31 (UTC)."],[],[]]