in python/ga4_setup/setup.py [0:0]
def get_measurement_protocol_secret_value(configuration: map, secret_display_name: str, transport: str = None):
"""
Retrieves the secret value for a given measurement protocol secret display name.
Args:
configuration: A dictionary containing the Google Analytics 4 property ID and data stream ID.
secret_display_name: The display name of the measurement protocol secret.
transport: The transport to use for the request. Defaults to None.
Returns:
The secret value for the measurement protocol secret, or None if the secret is not found.
Raises:
GoogleAnalyticsAdminError: If an error occurs while retrieving the measurement protocol secret.
"""
client = AnalyticsAdminServiceClient(transport=transport)
results = client.list_measurement_protocol_secrets(
parent=f"properties/{configuration['property_id']}/dataStreams/{configuration['stream_id']}"
)
for measurement_protocol_secret in results:
if measurement_protocol_secret.display_name == secret_display_name:
return measurement_protocol_secret.secret_value
return None