How to use the googleads.errors.GoogleAdsError 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 / v201708 / advanced_operations / add_ad_customizer.py View on Github external
feed_item_operations = [
      CreateFeedItemAddOperation(
          'Mars', '$1234.56', mars_date.strftime(time_format), adgroup_ids[0],
          ad_customizer_feed),
      CreateFeedItemAddOperation(
          'Venus', '$1450.00', venus_date.strftime(time_format),
          adgroup_ids[1], ad_customizer_feed)
  ]

  response = feed_item_service.mutate(feed_item_operations)

  if 'value' in response:
    for feed_item in response['value']:
      print 'Added FeedItem with ID %d.' % feed_item['feedItemId']
  else:
    raise errors.GoogleAdsError('No FeedItems were added.')
github googleads / googleads-python-lib / examples / adwords / v201506 / advanced_operations / create_and_attach_shared_keyword_set.py View on Github external
operations = [
      {
          'operator': 'ADD',
          'operand': campaign_set
      }
  ]

  response = campaign_shared_set_service.mutate(operations)

  if 'value' in response:
    print 'Shared set ID %d was attached to campaign ID %d' % (
        response['value'][0]['sharedSetId'], response['value'][0]['campaignId']
    )
  else:
    raise errors.GoogleAdsError('No campaign shared set was added.')
github googleads / googleads-python-lib / examples / adwords / v201607 / extensions / add_prices.py View on Github external
# Create an operation to add the feed.
  operations = [{
      'operator': 'ADD',
      'operand': customer_extension_setting
  }]

  # Add the price extension.
  response = customer_extension_setting_service.mutate(operations)

  # Print the results.
  if 'value' in response:
    print ('Extension setting with type "%s" was added to your account.'
           % response['value'][0]['extensionType'])
  else:
    raise errors.GoogleAdsError('No extension settings were added.')
github googleads / googleads-python-lib / examples / adwords / v201402 / campaign_management / add_keywords_in_bulk.py View on Github external
'text': keyword
            }
        }
    })

  # You can specify up to 3 job IDs that must successfully complete before
  # this job can be processed.
  policy = {
      'prerequisiteJobIds': []
  }

  # Call mutate to create a new job.
  response = mutate_job_service.mutate(operations, policy)

  if not response:
    raise errors.GoogleAdsError('Failed to submit a job; aborting.')

  job_id = response['id']
  print 'Job with ID %s was successfully created.' % job_id

  # Create selector to retrieve job status and wait for it to complete.
  selector = {
      'xsi_type': 'BulkMutateJobSelector',
      'jobIds': [job_id]
  }

  time.sleep(RETRY_INTERVAL)
  # Poll for job status until it's finished.
  print 'Retrieving job status...'
  for i in range(RETRIES_COUNT):
    job_status_response = mutate_job_service.get(selector)
    status = job_status_response[0]['status']
github googleads / googleads-python-lib / examples / adwords / v201502 / extensions / add_site_links_using_feeds.py View on Github external
'fieldId': PLACEHOLDER_FIELD_LINE_2_TEXT
          }
      ]
  }

  response = feed_mapping_service.mutate([
      {'operator': 'ADD', 'operand': feed_mapping}
  ])
  if 'value' in response:
    feed_mapping = response['value'][0]
    print ('Feed mapping with ID %s and placeholder type %s was saved for feed'
           ' with ID %s.' %
           (feed_mapping['feedMappingId'], feed_mapping['placeholderType'],
            feed_mapping['feedId']))
  else:
    raise errors.GoogleAdsError('No feed mappings were added.')

  # Construct a matching function that associates the sitelink feeditems to the
  # campaign, and set the device preference to Mobile. For more details, see the
  # matching function guide:
  # https://developers.google.com/adwords/api/docs/guides/feed-matching-functions
  matching_function_string = (
      'AND(IN(FEED_ITEM_ID, {%s}), EQUALS(CONTEXT.DEVICE, \'Mobile\'))' %
      re.sub(r'\[|\]|L', '', str(sitelinks_data['feedItemIds'])))

  campaign_feed = {
      'feedId': sitelinks_data['feedId'],
      'campaignId': campaign_id,
      'matchingFunction': {'functionString': matching_function_string},
      # Specifying placeholder types on the CampaignFeed allows the same feed
      # to be used for different placeholders in different Campaigns.
      'placeholderTypes': [PLACEHOLDER_SITELINKS]
github googleads / googleads-python-lib / examples / adwords / v201607 / advanced_operations / add_text_ad_with_upgraded_urls.py View on Github external
}]

  response = adgroup_ad_service.mutate(operations)

  if 'value' in response:
    for adgroup_ad in response['value']:
      print ('AdGroupAd with ID %s and display URL \'%s\'was added.'
             % (adgroup_ad['ad']['id'], adgroup_ad['ad']['displayUrl']))
      print 'Upgraded URL properties:'
      print 'Final Urls: %s' % adgroup_ad['ad']['finalUrls']
      print 'Final Mobile URLs: %s' % adgroup_ad['ad']['finalMobileUrls']
      print ('Tracking URL template: %s'
             % adgroup_ad['ad']['trackingUrlTemplate'])
      print 'Custom parameters: %s' % adgroup_ad['ad']['urlCustomParameters']
  else:
    raise errors.GoogleAdsError('Failed to create AdGroupAd.')
github googleads / googleads-python-lib / examples / adwords / v201802 / advanced_operations / add_expanded_text_ad_with_upgraded_urls.py View on Github external
'operand': text_adgroup_ad
  }]

  response = adgroup_ad_service.mutate(operations)

  if 'value' in response:
    for adgroup_ad in response['value']:
      print 'AdGroupAd with ID "%s" was added.' % adgroup_ad['ad']['id']
      print 'Upgraded URL properties:'
      print 'Final Urls: %s' % adgroup_ad['ad']['finalUrls']
      print 'Final Mobile URLs: %s' % adgroup_ad['ad']['finalMobileUrls']
      print ('Tracking URL template: %s'
             % adgroup_ad['ad']['trackingUrlTemplate'])
      print 'Custom parameters: %s' % adgroup_ad['ad']['urlCustomParameters']
  else:
    raise errors.GoogleAdsError('Failed to create AdGroupAd.')
github googleads / googleads-python-lib / examples / adwords / v201702 / advanced_operations / create_and_attach_shared_keyword_set.py View on Github external
operations = [{
      'operator': 'ADD',
      'operand': shared_set
  }]

  response = shared_set_service.mutate(operations)

  if response and response['value']:
    shared_set = response['value'][0]
    shared_set_id = shared_set['sharedSetId']

    print 'Shared set with ID %d and name "%s" was successfully added.' % (
        shared_set_id, shared_set['name']
    )
  else:
    raise errors.GoogleAdsError('No shared set was added.')

    # Add negative keywords to shared set.
  shared_criteria = [
      {
          'criterion': {
              'xsi_type': 'Keyword',
              'text': keyword,
              'matchType': 'BROAD'
          },
          'negative': True,
          'sharedSetId': shared_set_id
      } for keyword in keywords
  ]

  operations = [
      {
github googleads / googleads-python-lib / examples / adxbuyer / v201402 / campaign_management / add_placements_in_bulk.py View on Github external
# Poll for job status until it's finished.
  print 'Retrieving job status...'
  for i in range(RETRIES_COUNT):
    job_status_response = mutate_job_service.get(selector)
    status = job_status_response[0]['status']
    if status in ('COMPLETED', 'FAILED'):
      break
    print ('[%d] Current status is \'%s\', waiting %d seconds to retry...' %
           (i, status, RETRY_INTERVAL))
    time.sleep(RETRY_INTERVAL)

  if status == 'FAILED':
    raise errors.GoogleAdsError('Job failed with reason: \'%s\'' %
                                job_status_response[0]['failure_reason'])
  if status in ('PROCESSING', 'PENDING'):
    raise errors.GoogleAdsError('Job did not complete within %d seconds' %
                                (RETRY_INTERVAL * (RETRIES_COUNT - 1)))

  # Status must be COMPLETED.
  # Get the job result. Here we re-use the same selector.
  result_response = mutate_job_service.getResult(selector)

  # Output results.
  index = 0
  for result in result_response['SimpleMutateResult']['results']:
    if 'PlaceHolder' in result:
      print 'Operation [%d] - FAILED' % index
    else:
      print 'Operation [%d] - SUCCEEDED' % index
    index += 1

  # Output errors
github googleads / googleads-python-lib / examples / adwords / v201601 / campaign_management / add_keywords_in_bulk.py View on Github external
'text': keyword
            }
        }
    })

  # You can specify up to 3 job IDs that must successfully complete before
  # this job can be processed.
  policy = {
      'prerequisiteJobIds': []
  }

  # Call mutate to create a new job.
  response = mutate_job_service.mutate(operations, policy)

  if not response:
    raise errors.GoogleAdsError('Failed to submit a job; aborting.')

  job_id = response['id']
  print 'Job with ID %s was successfully created.' % job_id

  # Create selector to retrieve job status and wait for it to complete.
  selector = {
      'xsi_type': 'BulkMutateJobSelector',
      'jobIds': [job_id]
  }

  time.sleep(RETRY_INTERVAL)
  # Poll for job status until it's finished.
  print 'Retrieving job status...'
  for i in range(RETRIES_COUNT):
    job_status_response = mutate_job_service.get(selector)
    status = job_status_response[0]['status']