How to use the googleads.adwords function in googleads

To help you get started, we’ve selected a few googleads examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleads / googleads-python-lib / examples / adwords / v201802 / basic_operations / get_campaigns_with_awql.py View on Github external
def main(client):
  # Initialize appropriate service.
  campaign_service = client.GetService('CampaignService', version='v201802')

  # Construct query and get all campaigns.
  query = (adwords.ServiceQueryBuilder()
           .Select('Id', 'Name', 'Status')
           .Where('Status').EqualTo('ENABLED')
           .OrderBy('Name')
           .Limit(0, PAGE_SIZE)
           .Build())

  for page in query.Pager(campaign_service):
    # Display results.
    if 'entries' in page:
      for campaign in page['entries']:
        print ('Campaign with id "%s", name "%s", and status "%s" was '
               'found.' % (campaign['id'], campaign['name'],
                           campaign['status']))
    else:
      print 'No campaigns were found.'
github googleads / googleads-python-lib / examples / adwords / v201702 / campaign_management / graduate_trial.py View on Github external
trial_operation = {'operator': 'SET', 'operand': trial}

  # Update the trial.
  trial = trial_service.mutate([trial_operation])['value'][0]

  # Graduation is a synchronous operation, so the campaign is already ready. If
  # you promote instead, make sure to see the polling scheme demonstrated in
  # add_trial.py to wait for the asynchronous operation to finish.
  print ('Trial ID %d graduated. Campaign %d was given a new budget ID %d and '
         'is no longer dependent on this trial.' % (
             trial['id'], trial['trialCampaignId'], budget_id))


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()

  main(adwords_client, TRIAL_ID)
github googleads / googleads-python-lib / examples / adwords / v201607 / advanced_operations / add_html5_ad.py View on Github external
# Display results.
  for ad in ads['value']:
    print ('New HTML5 Ad with id \'%s\' and of display url \'%s\' was added.'
           % (ad['ad']['id'], ad['ad']['displayUrl']))


def GetBase64EncodedHTML5ZipFromUrl(url):
  """Retrieve zip file from the given URL."""
  response = urllib2.urlopen(url)
  return base64.b64encode(response.read())


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()

  main(adwords_client, AD_GROUP_ID)
github googleads / googleads-python-lib / examples / adwords / v201607 / basic_operations / get_keywords.py View on Github external
print ('Keyword ID \'%d\', type \'%s\', text \'%s\', and match type '
               '\'%s\' was found.' % (
                   keyword['criterion']['id'],
                   keyword['criterion']['type'],
                   keyword['criterion']['text'],
                   keyword['criterion']['matchType']))
    else:
      print 'No keywords were found.'
    offset += PAGE_SIZE
    selector['paging']['startIndex'] = str(offset)
    more_pages = offset < int(page['totalNumEntries'])


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()

  main(adwords_client, ADGROUP_ID)
github googleads / googleads-python-lib / examples / adwords / v201502 / remarketing / add_conversion_tracker.py View on Github external
}
  ]
  conversion_trackers = conversion_tracker_service.mutate(operations)

  # Display results.
  for conversion_tracker in conversion_trackers['value']:
    print ('Conversion tracker with id \'%s\', name \'%s\', status \'%s\' '
           'and category \'%s\' and snippet \n\'%s\'\n was added.\n' %
           (conversion_tracker['id'], conversion_tracker['name'],
            conversion_tracker['status'], conversion_tracker['category'],
            conversion_tracker['snippet']))


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()

  main(adwords_client)
github googleads / googleads-python-lib / examples / adwords / v201506 / account_management / get_account_hierarchy.py View on Github external
accounts[account['customerId']] = account
      if account['customerId'] not in parent_links:
        root_account = account
    # Display account tree.
    if root_account:
      print 'CustomerId, Name'
      DisplayAccountTree(root_account, accounts, child_links, 0)
    else:
      print 'Unable to determine a root account'
  else:
    print 'No serviced accounts were found'


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()
  main(adwords_client)
github googleads / googleads-python-lib / examples / adwords / v201702 / campaign_management / add_draft.py View on Github external
'operand': {
          'campaignId': draft_campaign_id,
          'criterion': criterion
      }
  }

  criterion = campaign_criterion_service.mutate([criterion_operation])[
      'value'][0]

  print ('Draft updated to include criteria in campaign with ID %d' %
         draft_campaign_id)


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()

  main(adwords_client, BASE_CAMPAIGN_ID)
github googleads / googleads-python-lib / examples / adxbuyer / v201402 / basic_operations / delete_placement.py View on Github external
}
      }
  ]
  result = ad_group_criterion_service.mutate(operations)

  # Display results.
  for criterion in result['value']:
    print ('Ad group criterion with ad group id \'%s\', criterion id \'%s\', '
           'and type \'%s\' was deleted.'
           % (criterion['adGroupId'], criterion['criterion']['id'],
              criterion['criterion']['Criterion.Type']))


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()

  main(adwords_client, AD_GROUP_ID, CRITERION_ID)
github googleads / googleads-python-lib / examples / adwords / v201607 / extensions / add_prices.py View on Github external
'description': description,
      'finalUrls': {'urls': [final_url]},
      'price': {
          'money': {
              'microAmount': price_in_micros,
          },
          'currencyCode': currency_code
      },
      'priceUnit': price_unit,
      'xsi_type': 'PriceTableRow'
  }


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()
  main(adwords_client, CAMPAIGN_ID)
github googleads / googleads-python-lib / examples / adwords / v201605 / reporting / download_criteria_report_as_string_with_awql.py View on Github external
# Create report query.
  report_query = ('SELECT CampaignId, AdGroupId, Id, Criteria, CriteriaType, '
                  'FinalUrls, Impressions, Clicks, Cost '
                  'FROM CRITERIA_PERFORMANCE_REPORT '
                  'WHERE Status IN [ENABLED, PAUSED] '
                  'DURING LAST_7_DAYS')

  print report_downloader.DownloadReportAsStringWithAwql(
      report_query, 'CSV', skip_report_header=False, skip_column_header=False,
      skip_report_summary=False, include_zero_impressions=True)


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()

  main(adwords_client)