您可以使用展示广告和Video 360 API:管理自定义出价 实现。您可以创建自定义出价算法、上传并验证 单个脚本,并为资源分配特定算法作为其出价 策略
本页介绍了如何创建、更新和分配自定义出价算法 展示广告和Video 360 API。每个部分都提供了一个代码示例。
创建自定义出价算法
CustomBiddingAlgorithm 对象表示
算法,您可以将其分配给订单项,以便在其出价策略中使用。这个
对象包含详细的算法信息,例如
customBiddingAlgorithmType、
entityStatus和
customBiddingAlgorithmState。您可以创建
CustomBiddingScript 对象作为算法的子资源
使用。
以下示例展示了如何创建基于脚本的自定义出价 算法:
Python
# Create a custom bidding algorithm object. custom_bidding_algorithm_obj = { 'advertiserId': advertiser-id, 'displayName': display-name, 'entityStatus': 'ENTITY_STATUS_ACTIVE', 'customBiddingAlgorithmType': 'SCRIPT_BASED' } # Create the custom bidding algorithm. response = service.customBiddingAlgorithms().create( body=algorithm_obj ).execute() # Display the new custom bidding algorithm. print(f'The following Custom Bidding Algorithm was created: {response}')
管理算法访问权限
自定义出价算法可以归合作伙伴或广告客户所有。算法
所有子公司所拥有的资源都可以被该合作伙伴及其子公司访问和修改。
sharedAdvertiserIds 字段中列出的广告客户。
该广告主可以通过它来访问和修改归广告主所有的算法
广告客户及其父级合作伙伴,但不能与其他广告客户共享。
如果只对一个广告客户使用该算法,请将该算法分配给
将广告客户设为所有者,并填写 advertiserId 字段。
否则,请将广告客户的父级合作伙伴指定为所有者,并分配
partnerId 字段,然后向广告客户授予
sharedAdvertiserIds 字段中的值。
上传脚本
创建自定义出价算法后,请为该算法创建脚本 算法。基于脚本的自定义出价算法采用用户提供 脚本来评估展示机会的价值。 简单脚本示例和 高级字段的 展示广告与Video 360 帮助中心。
以下部分介绍了如何将新脚本或更新后的脚本添加到自定义 出价算法。
检索脚本资源位置
首先,检索自定义出价下的可用资源位置
该算法资源
customBiddingAlgorithms.uploadScript 方法。这个
请求会返回 CustomBiddingScriptRef 对象,其中包含
资源名称。您可以
将您的脚本文件上传到
资源名称然后使用自定义出价脚本引用对象
创建脚本资源。
下面是一个有关如何检索可用资源的示例 地点:
Python
# Retrieve a usable custom bidding script reference # object. custom_bidding_script_ref = service.customBiddingAlgorithms().uploadScript( customBiddingAlgorithmId=custom-bidding-algorithm-id, advertiserId=advertiser-id ).execute() # Display the new custom bidding script reference object. print('The following custom bidding script reference object was retrieved:' f'{custom_bidding_script_ref}')
上传脚本文件
检索到可用的资源位置后,将脚本文件上传到该位置
地理位置Video 360 系统,
media.upload 方法。此方法支持
简单上传(需要查询参数)
uploadType=media。
以下示例展示了如何上传给定的 已检索到自定义出价脚本参考对象:
Python
# Create a media upload object. media = MediaFileUpload(script-path) # Create upload request. upload_request = service.media().upload( resourceName=resource-name, media_body=media) # Override response handler to expect null response. upload_request.postproc = HttpRequest.null_postproc # Upload script to resource location given in retrieved custom bidding # script reference object. upload_request.execute()
创建脚本对象
脚本文件上传完毕后,请使用以下属性创建自定义出价脚本资源
customBiddingAlgorithms.scripts.create 方法。通过
请求中传递的 CustomBiddingScript 对象只能
将 CustomBiddingScriptRef 对象添加为
script 字段的值。这会将所上传的
包含新的脚本资源的脚本文件。
以下示例展示了如何创建脚本文件:
Python
# Create a custom bidding script object. script_obj = { 'script': custom-bidding-script-ref } # Create the custom bidding script. response = service.customBiddingAlgorithms().scripts().create( customBiddingAlgorithmId=custom-bidding-algorithm-id, advertiserId=advertiser-id, body=script_obj).execute() # Display the new custom bidding script object. print(f'The following custom bidding script was created: {response}')
创建自定义出价脚本资源后,展示广告系列和Video 360 会处理
脚本,以确保可以成功使用它来对展示进行评分。
通过脚本对象的
state 字段。接受新脚本后,自定义
出价算法开始使用脚本对展示机会价值进行评分。这个
因此请务必先更新算法
创建新的脚本资源
指定自定义出价算法
创建自定义出价算法后,请上传可接受的脚本,并满足 必要要求后,您可以将自定义 出价算法并应用到订单项或广告订单的出价策略。
您可以使用自定义出价算法,
最大限度地增加支出和
为效果目标分配 BIDDING_STRATEGY_PERFORMANCE_GOAL_TYPE_CUSTOM_ALGO 出价策略
并将自定义出价算法 ID 添加到
performanceGoalType 和
customBiddingAlgorithmId 字段。
根据出价策略的不同,或许会显示其他出价参数,
必填字段。
下例说明了如何将订单项更新为使用 采用指定自定义出价算法的支出出价策略:
Python
# Create the new bid strategy object. bidding_strategy = { 'maximizeSpendAutoBid': { 'performanceGoalType': 'BIDDING_STRATEGY_PERFORMANCE_GOAL_TYPE_CUSTOM_ALGO', 'customBiddingAlgorithmId': custom-bidding-algorithm-id } } # Create a line item object assigning the new bid strategy. line_item_obj = {'bidStrategy': bidding_strategy} # Update the line item with a new bid strategy. response = service.advertisers().lineItems().patch( advertiserId=advertiser-id, lineItemId=line-item-id, updateMask='bidStrategy', body=line_item_obj).execute() # Display the line item's new bid strategy print(f'Line Item {response["name"]} is now using the following bid' f' strategy: {response["bidStrategy"]}.')