Restrict a feed item to a geo target location.

  Args:
    client: An AdWordsClient instance.
    feed_item: A FeedItem.
    location_id: The Id of the location to restrict to.

def RestrictFeedItemToGeoTarget(client, feed_item, location_id):
  """Restrict a feed item to a geo target location.

  Args:
    client: An AdWordsClient instance.
    feed_item: A FeedItem.
    location_id: The Id of the location to restrict to.
  """
  # Retrieve the FeedItemTargetService
  feed_item_target_service = client.GetService(
      'FeedItemTargetService', version='v201809')

  # Optional: Restrict the first feed item to only serve with ads for the
  # specified geo target.
  criterion_target = {
      'xsi_type': 'FeedItemCriterionTarget',
      'feedId': feed_item['feedId'],
      'feedItemId': feed_item['feedItemId'],
      # These IDs can be found in the documentation or retrieved with the
      # LocationCriterionService.
      'criterion': {
          'xsi_type': 'Location',
          'id': location_id
      }
  }

  operation = {'operator': 'ADD', 'operand': criterion_target}

  response = feed_item_target_service.mutate([operation])
  new_location_target = response['value'][0]
  print('Feed item target for feed ID %d and feed item ID %d was created to '
        'restrict serving to location ID %d.' %
        (new_location_target['feedId'],
         new_location_target['feedItemId'],
         new_location_target['criterion']['id']))