取得屬性(Python)
最後更新: 2026年9月30日
- 主題:
- APIs/SDKs
建立對象:
- 開發人員
說明
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)
自動翻譯
使用「語言選取器」檢視此頁面的英文版。
翻譯是否有幫助?
此內容有用嗎?
詳盡意見回饋選項