설명서Target 개발자 안내서

속성 가져오기(Python)

마지막 업데이트: 2024년 7월 20일
  • 주제:
  • APIs/SDKs

작성 대상:

  • 개발자

설명

get_attributes()은(는) Target에서 실험과 개인화된 경험을 가져오고 특성 값을 추출하는 데 사용됩니다.

방법

getAttributes

target_client_instance.get_attributes(mbox_names, options)

매개 변수

이름유형필수기본값설명
mbox_nameslist[str]예없음mbox 이름 목록
optionsdict아니요없음오퍼 가져오기에 사용된 것과 동일한 옵션

Attributeprovider

target_client.get_attributes()이(가) 반환한 AttributesProvider에는 다음 메서드가 있습니다.

방법반환 유형설명
get_value(mbox_name, key)any지정된 mbox 이름 및 속성 키에 대한 값을 반환합니다.
as_object(mbox_name)dict키 값 쌍이 있는 단순 json 개체 반환
get_response()TargetDeliveryResponseget_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