Obtener atributos (Python)
Última actualización: 20 de julio de 2024
- Temas:
- APIs/SDKs
Creado para:
- Desarrollador
Descripción
get_attributes()
se usa para recuperar experimentación y experiencias personalizadas de Target y extraer valores de atributos.
Método
getAttributes
target_client_instance.get_attributes(mbox_names, options)
Parámetros
Nombre | Tipo | Requerido | Valor predeterminado | Descripción |
---|---|---|---|---|
mbox_names | list[str] | Sí | Ninguna | Una lista de nombres de mbox |
opciones | dict | No | Ninguna | Se usan las mismas opciones para Obtener ofertas |
AttributesProvider
El AttributesProvider
devuelto por target_client.get_attributes()
tiene los siguientes métodos:
Método | Tipo de devolución | Descripción |
---|---|---|
get_value(mbox_name, key) | any | Devuelve el valor de un nombre de mbox y una clave de atributo especificados |
as_object(mbox_name) | dict | Devuelve un objeto json simple con pares de valor clave |
get_response() | TargetDeliveryResponse | Devuelve el objeto de respuesta normalmente devuelto por get_offers |
Ejemplo
Python
def client_ready_callback():
context = Context(channel=ChannelType.WEB)
mboxes = [MboxRequest(name="a1-serverside-ab", index=1)]
execute = ExecuteRequest(mboxes=mboxes)
delivery_request = DeliveryRequest(context=context, execute=execute)
get_attributes_options = {
"request": delivery_request
}
attributes_provider = target_client.get_attributes(["demo-engineering-flags"], get_attributes_options)
# returns just the value of searchProviderId from the demo-engineering-flags mbox offer
search_provider_id = attributes_provider.get_value("demo-engineering-flags", "searchProviderId")
# returns a simple dict object representing the demo-engineering-flags mbox offer
engineering_flags = attributes_provider.as_object("demo-engineering-flags")
""" the value of engineeringFlags looks like this
{
"cdnHostname": "cdn.cloud.corp.net",
"searchProviderId": 143,
"hasLegacyAccess": false
}
"""
asset_url = "http://{}/path/to/asset".format(engineering_flags.get("cdnHostname"))
client_options = {
"client": "acmeclient",
"organization_id": "1234567890@AdobeOrg",
"events": {
"client_ready": client_ready_callback
}
}
target_client = TargetClient.create(client_options)
recommendation-more-help
6906415f-169c-422b-89d3-7118e147c4e3