我编写了一个脚本,每天将价格附加信息上传到我的广告系列中。但是由于某种原因,应用运算符SET
导致旧扩展名被删除。
我想运行一次(使用操作符ADD
),然后使用SET
更新扩展名。我该怎么办?
以下代码:
def add_price_extension(adwords, campaign_id, table_rows):
# table_rows as an argument to the function!
if len(table_rows) < 3:
raise errors.GoogleAdsError('Not enough table rows (minimum: 3)')
elif len(table_rows) > 8:
raise errors.GoogleAdsError('Too many table rows (maximum: 8)')
service = adwords.client.GetService('CampaignExtensionSettingService', version = 'v201806')
operations = [{
'operator': 'SET',
'operand': {
'campaignId': campaign_id,
'extensionType': 'PRICE',
'extensionSetting': {
'extensions': [{
'xsi_type': 'PriceFeedItem',
'priceExtensionType': 'PRODUCT_CATEGORIES',
'language': 'pt-BR',
'campaignTargeting': {
'TargetingCampaignId': campaign_id
},
'scheduling': {
'feedItemSchedules': [
{
'dayOfWeek': day_of_week,
'startHour': 0,
'startMinute': 'ZERO',
'endHour': 24,
'endMinute': 'ZERO',
} for day_of_week in [
'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY',
'FRIDAY', 'SATURDAY', 'SUNDAY'
]
]
},
'tableRows': table_rows,
'priceQualifier': 'FROM',
}]
}
}
}]
response = service.mutate(operations)
if 'value' in response:
print('Extension setting with type "%s" was added to the campaign with ID %d.'
% (response['value'][0]['extensionType'], campaign_id))
else:
raise errors.GoogleAdsError('No extension settings were added.')
我尝试使用名为FIRST_TIME的常量,并在第一次运行时将其设置为True
,然后将其设置为False
。但是我对将其传递给函数有些困惑。
FIRST_TIME = True
def add_price_extension(adwords, campaign_id, table_rows, first_time = FIRST_TIME):
...
operations = [{
if first_time:
'operator': 'ADD'
else:
'operator': 'SET',
'operand': {
...
谢谢。