获取属性(Python)

描述

get_attributes()用于从Target获取试验性和个性化体验并提取属性值。

方法

getAttributes

target_client_instance.get_attributes(mbox_names, options)

参数

名称
类型
必需
默认
描述
mbox_names
列表[str]
mbox名称列表
options
dict
获取选件使用的选项相同

属性提供程序

target_client.get_attributes()返回的AttributesProvider具有以下方法:

方法
返回类型
描述
get_value(mbox_name, key)
any
返回指定mbox名称和属性键的值
as_object(mbox_name)
dict
返回具有键值对的简单json对象
get_response()
TargetDeliveryResponse
返回get_offers通常返回的响应对象

示例

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