def main(argv):
    # Authenticate and construct service.
    service, config, _ = shopping_common.init(argv, __doc__)
    merchant_id = config['merchantId']

    name = 'feed%s' % shopping_common.get_unique_id()
    datafeed = datafeed_sample.create_datafeed_sample(config, name)

    # Add datafeed.
    request = service.datafeeds().insert(merchantId=merchant_id, body=datafeed)

    result = request.execute()

    print('Datafeed with name "%s" and ID %s was created.' %
          (result['name'], result['id']))
예제 #2
0
def main(argv):
  # Authenticate and construct service.
  service, config, _ = shopping_common.init(argv, __doc__)
  merchant_id = config['merchantId']

  batch = BatchHttpRequest(callback=datafeed_inserted)

  for _ in range(BATCH_SIZE):
    name = 'feed%s' % shopping_common.get_unique_id()
    datafeed = datafeed_sample.create_datafeed_sample(config, name)

    # Add datafeed to the batch.
    batch.add(service.datafeeds().insert(merchantId=merchant_id,
                                         body=datafeed))
  try:
    batch.execute()
  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')
예제 #3
0
def main(argv):
  # Authenticate and construct service.
  service, config, _ = shopping_common.init(argv, __doc__)
  merchant_id = config['merchantId']

  try:
    name = 'feed%s' % shopping_common.get_unique_id()
    datafeed = datafeed_sample.create_datafeed_sample(config, name)

    # Add datafeed.
    request = service.datafeeds().insert(merchantId=merchant_id, body=datafeed)

    result = request.execute()

    print('Datafeed with name "%s" and ID "%s" was created.' % (result['name'],
                                                                result['id']))

  except client.AccessTokenRefreshError:
    print('The credentials have been revoked or expired, please re-run the '
          'application to re-authorize')
def main(argv):
    # Authenticate and construct service.
    service, config, _ = shopping_common.init(argv, __doc__)
    merchant_id = config['merchantId']

    batch = {
        'entries': [{
            'batchId':
            i,
            'merchantId':
            merchant_id,
            'method':
            'insert',
            'datafeed':
            datafeed_sample.create_datafeed_sample(
                config, 'feed%s' % shopping_common.get_unique_id()),
        } for i in range(BATCH_SIZE)],
    }

    request = service.datafeeds().custombatch(body=batch)
    result = request.execute()

    if result['kind'] == 'content#datafeedsCustomBatchResponse':
        entries = result['entries']
        for entry in entries:
            if not shopping_common.json_absent_or_false(entry, 'datafeed'):
                print('Datafeed %s with name "%s" created.' %
                      (entry['datafeed']['id'], entry['datafeed']['name']))
            elif not shopping_common.json_absent_or_false(entry, 'errors'):
                print('Errors for batch entry %d:' % entry['batchId'])
                print(
                    json.dumps(entry['errors'],
                               sort_keys=True,
                               indent=2,
                               separators=(',', ': ')))
    else:
        print('There was an error. Response: %s' % result)