我尝试使用带有官方库的Google Adwords API:https://github.com/googleads/googleads-python-lib
我在Google Adwords上使用经理帐户,并希望使用客户的帐户。
我可以获得所有的Adwords帐户ID(例如123-456-7891),但是我不知道如何将帐户ID作为参数传递给我的Google Adwords函数。
这是我的主要功能:
def main(argv):
adwords_client = adwords.AdWordsClient.LoadFromStorage(path="googleads.yaml")
add_campaign(adwords_client)
我在官方示例中看到任何帐户ID参数,如下所示:
import datetime
import uuid
from googleads import adwords
def add_campaign(client):
# Initialize appropriate services.
campaign_service = client.GetService('CampaignService', version='v201809')
budget_service = client.GetService('BudgetService', version='v201809')
# Create a budget, which can be shared by multiple campaigns.
budget = {
'name': 'Interplanetary budget #%s' % uuid.uuid4(),
'amount': {
'microAmount': '50000000'
},
'deliveryMethod': 'STANDARD'
}
budget_operations = [{
'operator': 'ADD',
'operand': budget
}]
# Add the budget.
budget_id = budget_service.mutate(budget_operations)['value'][0][
'budgetId']
# Construct operations and add campaigns.
operations = [{
'operator': 'ADD',
'operand': {
'name': 'Interplanetary Cruise #%s' % uuid.uuid4(),
# Recommendation: Set the campaign to PAUSED when creating it to
# stop the ads from immediately serving. Set to ENABLED once you've
# added targeting and the ads are ready to serve.
'status': 'PAUSED',
'advertisingChannelType': 'SEARCH',
'biddingStrategyConfiguration': {
'biddingStrategyType': 'MANUAL_CPC',
},
'endDate': (datetime.datetime.now() +
datetime.timedelta(365)).strftime('%Y%m%d'),
# Note that only the budgetId is required
'budget': {
'budgetId': budget_id
},
'networkSetting': {
'targetGoogleSearch': 'true',
'targetSearchNetwork': 'true',
'targetContentNetwork': 'false',
'targetPartnerSearchNetwork': 'false'
},
# Optional fields
'startDate': (datetime.datetime.now() +
datetime.timedelta(1)).strftime('%Y%m%d'),
'frequencyCap': {
'impressions': '5',
'timeUnit': 'DAY',
'level': 'ADGROUP'
},
'settings': [
{
'xsi_type': 'GeoTargetTypeSetting',
'positiveGeoTargetType': 'DONT_CARE',
'negativeGeoTargetType': 'DONT_CARE'
}
]
}
}, {
'operator': 'ADD',
'operand': {
'name': 'Interplanetary Cruise banner #%s' % uuid.uuid4(),
'status': 'PAUSED',
'biddingStrategyConfiguration': {
'biddingStrategyType': 'MANUAL_CPC'
},
'endDate': (datetime.datetime.now() +
datetime.timedelta(365)).strftime('%Y%m%d'),
# Note that only the budgetId is required
'budget': {
'budgetId': budget_id
},
'advertisingChannelType': 'DISPLAY'
}
}]
campaigns = campaign_service.mutate(operations)
如何告诉Adwords API我要在哪个帐户中添加此广告系列?
感谢您的帮助!
答案 0 :(得分:0)
好的,不好,我错过了一种文档记录方法(http://googleads.github.io/googleads-python-lib/googleads.adwords.AdWordsClient-class.html#SetClientCustomerId)。
from selenium import webdriver
import time
import pyautogui
url = 'https://www.morningstar.com/stocks/xnas/tsla/quote.html'
browser = webdriver.Firefox()
browser.get(url)
time.sleep(7)
pyautogui.click(139, 833, button='left')
time.sleep(10)
pyautogui.click(973, 289, button='left')
time.sleep(2)
pyautogui.click(1649, 236, button='left')
time.sleep(1)
pyautogui.typewrite(['down'])
time.sleep(1)
pyautogui.typewrite(['enter'])
browser.close()
现在,客户ID与AdwordsClient变量(作为“客户”)相关联,并被设置为其他功能的参数。