Google Code offered in: English - Español - 日本語 - 한국어 - Português - Pусский - 中文(简体) - 中文(繁體)
The production AdWords API services are available at the following URLs:
https://adwords.google.com/api/adwords/cm/https://adwords.google.com/api/adwords/job/To access the sandbox AdWords API services, just replace adwords.google.com with adwords-sandbox.google.com (read more about the Sandbox in the v13 documentation). Example:
To connect to the AdWords API v2009 web services and make a request:
All calls to AdWords API v2009 require a secure authentication token, which you specify using the authToken header. You retrieve this token by posting your account login and password to the ClientLogin API. The following code snippet uses the auth_token module provided in the AdWords API Python samples.
import aw_api.auth_token as auth_token authtoken = auth_token.AuthToken(YOUR_EMAIL, YOUR_PASSWORD).GetAuthToken()
Before sending any requests to the AdWords API, you must first establish a connection to the web services you plan to use. First, you set the request headers:
header = {
'authToken': authtoken, # Acquired in the code above
'userAgent': 'YOUR_COMPANY_NAME: Getting Started with AdWords API'
'developerToken': 'INSERT_DEVELOPER_TOKEN_HERE'
'applicationToken': 'INSERT_APPLICATION_TOKEN_HERE'
}
After defining the headers, set up the connection to an AdWords API web service:
# Connect to CampaignService import aw_api.message_handler as message_handler import aw_api.v200909.CampaignService_services as cmp_srvcs namespace = 'https://adwords.google.com/api/adwords/cm/v200909' url = ('https://adwords-sandbox.google.com/api/adwords/cm/v200909' '/CampaignService') service = message_handler.GetServiceConnection(header, namespace, url, 'CampaignService', cmp_srvcs.CampaignServiceLocator(), debug=False)
After you've established a connection to an AdWords API web service (CampaignService in this example), perform an operation. The following code defines a campaign and the operation to add it:
campaign = { 'name': 'Test Campaign - %s' % time.time(), 'status': 'ACTIVE', 'biddingStrategy': cmp_srvcs.ns0.ManualCPC_Def('ManualCPC').pyclass, 'budget': { 'period': 'DAILY', 'amount': { 'currencyCode': 'USD', 'microAmount': '50000000' }, 'deliveryMethod': 'STANDARD' } } request = { 'operations': [ {'operator': 'ADD', 'operand': campaign} ] }
Finally, send the request to CampaignService. The mutate operation returns the results of the operations performed on the specified campaigns.
campaigns = message_handler.UnpackResponseAsTuple(service.mutate(
message_handler.SetRequestParams(cmp_srvcs.mutateRequest(), (request,))))
# Display new campaign.
for campaign in campaigns['rval']['value']:
print ('New campaign with name \'%s\' and id \'%s\' was created.'
% (campaign['name'], campaign['id']))