def main(argv):
  # Authenticate and construct service.
  service, flags = sample_tools.init(
      argv, 'content', 'v2', __doc__, __file__, parents=[argparser])
  merchant_id = flags.merchant_id

  try:
    name = 'account%s' % shopping_common.get_unique_id()
    account = {
        'name': name,
        'websiteUrl': 'https://%s.example.com/' % (name,)
    }

    # Add account.
    request = service.accounts().insert(merchantId=merchant_id,
                                        body=account)

    result = request.execute()

    print ('Created account ID "%s" for MCA "%s".' %
           (result['id'], merchant_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, flags = sample_tools.init(argv,
                                       'content',
                                       'v2',
                                       __doc__,
                                       __file__,
                                       parents=[argparser])
    merchant_id = flags.merchant_id

    try:
        name = 'account%s' % shopping_common.get_unique_id()
        account = {
            'name': name,
            'websiteUrl': 'https://%s.example.com/' % (name, )
        }

        # Add account.
        request = service.accounts().insert(merchantId=merchant_id,
                                            body=account)

        result = request.execute()

        print('Created account ID "%s" for MCA "%s".' %
              (result['id'], merchant_id))

    except client.AccessTokenRefreshError:
        print(
            'The credentials have been revoked or expired, please re-run the '
            'application to re-authorize')
Exemplo n.º 3
0
def main(argv):
    # Authenticate and construct service.
    service, flags = sample_tools.init(argv,
                                       'content',
                                       'v2',
                                       __doc__,
                                       __file__,
                                       parents=[argparser])
    merchant_id = flags.merchant_id
    account_id = flags.account_id

    try:
        new_name = 'updated-account%s' % (shopping_common.get_unique_id(), )
        request = service.accounts().patch(merchantId=merchant_id,
                                           accountId=account_id,
                                           body={'name': new_name})

        result = request.execute()
        print('Account with id "%s" was updated with new name "%s".' %
              (account_id, result['name']))

    except client.AccessTokenRefreshError:
        print(
            'The credentials have been revoked or expired, please re-run the '
            'application to re-authorize')
Exemplo n.º 4
0
def main(argv):
    # Authenticate and construct service.
    service, flags = sample_tools.init(argv,
                                       'content',
                                       'v2',
                                       __doc__,
                                       __file__,
                                       parents=[argparser])
    merchant_id = flags.merchant_id

    batch = BatchHttpRequest(callback=account_inserted)

    for _ in range(BATCH_SIZE):
        name = 'account%s' % shopping_common.get_unique_id()
        account = {
            'name': name,
            'websiteUrl': 'https://%s.example.com/' % (name, )
        }
        # Add account to the batch.
        batch.add(service.accounts().insert(merchantId=merchant_id,
                                            body=account))
    try:
        batch.execute()
    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']
    shopping_common.check_mca(config, True)

    try:
        name = 'account%s' % shopping_common.get_unique_id()
        account = {
            'name': name,
            'websiteUrl': 'https://%s.example.com/' % (name, )
        }

        # Add account.
        request = service.accounts().insert(merchantId=merchant_id,
                                            body=account)

        result = request.execute()

        print('Created account ID "%s" for MCA "%s".' %
              (result['id'], merchant_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, flags = sample_tools.init(
      argv, 'content', 'v2', __doc__, __file__, parents=[argparser])
  merchant_id = flags.merchant_id

  batch = { "entries": [ ] }

  for i in range(BATCH_SIZE):
    offer_id = 'book#%s' % shopping_common.get_unique_id()
    product = {
        'offerId': offer_id,
        'title': 'This is book number %d' % (i,),
        'description': 'Sample book',
        'link': 'http://%s/book.html' % ROOT_URL,
        'imageLink': 'http://my-book-shop.com/book.jpg',
        'contentLanguage': CONTENT_LANGUAGE,
        'targetCountry': TARGET_COUNTRY,
        'channel': CHANNEL,
        'availability': 'in stock',
        'condition': 'new',
        'googleProductCategory': 'Media > Books',
        'gtin': '9780007350896',
        'price': {'value': '%d.50' % (i,), 'currency': 'USD'},
        'shipping': [{
            'country': 'US',
            'service': 'Standard shipping',
            'price': {'value': '0.99', 'currency': 'USD'}
        }],
        'shippingWeight': {'value': '200', 'unit': 'grams'}
    }
    # Add product to the batch.
    batch['entries'].append({
      'batchId': i,
      'merchantId': merchant_id,
      'method': 'insert',
      'product': product
    })

  try:
    request = service.products().custombatch(body=batch)
    result = request.execute()

    if result['kind'] == 'content#productsCustomBatchResponse':
      entries = result['entries']
      for entry in entries:
        if 'product' in entry:
          product = entry['product']
          print ('Product with offerId "%s" and title "%s" was created.' %
                (product['offerId'], product['title']))
        elif 'errors' in entry:
          print entry['errors']
    else:
      print 'There was an error. Response: %s' % (result)
  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')
Exemplo n.º 7
0
def main(argv):
    # Authenticate and construct service.
    service, flags = sample_tools.init(argv,
                                       'content',
                                       'v2',
                                       __doc__,
                                       __file__,
                                       parents=[argparser])
    merchant_id = flags.merchant_id

    try:
        name = 'feed%s' % shopping_common.get_unique_id()
        datafeed = {
            'name': name,
            'contentType': 'products',
            'attributeLanguage': 'en',
            'contentLanguage': 'en',
            'intendedDestinations': ['Shopping'],
            # The file name must be unique per account. We only use unique names in
            # these examples, so it's not an issue here.
            'fileName': name,
            'targetCountry': 'US',
            # You can schedule monthly, weekly or daily.
            #
            # Monthly - set day of month ('dayOfMonth') and hour ('hour')
            # Weekly - set day of week ('weekday') and hour ('hour')
            # Daily - set just the hour ('hour')
            'fetchSchedule': {
                'weekday': 'monday',
                'hour': 6,
                'timeZone': 'America/Los_Angeles',
                'fetchUrl': 'https://feeds.myshop.com/' + name
            },
            'format': {
                'fileEncoding': 'utf-8',
                'columnDelimiter': 'tab',
                'quotingMode': 'value quoting'
            }
        }

        # 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']

    offer_id = 'book#%s' % shopping_common.get_unique_id()
    product = product_sample.create_product_sample(config, offer_id)

    # Add product.
    request = service.products().insert(merchantId=merchant_id, body=product)

    result = request.execute()
    print('Product with offerId "%s" and title "%s" was created.' %
          (result['offerId'], result['title']))
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']))
def main(argv):
    # Authenticate and construct service.
    service, flags = sample_tools.init(argv, "content", "v2", __doc__, __file__, parents=[argparser])
    merchant_id = flags.merchant_id
    account_id = flags.account_id

    try:
        new_name = "updated-account%s" % (shopping_common.get_unique_id(),)
        request = service.accounts().patch(merchantId=merchant_id, accountId=account_id, body={"name": new_name})

        result = request.execute()
        print('Account with id "%s" was updated with new name "%s".' % (account_id, result["name"]))

    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, flags = sample_tools.init(
      argv, 'content', 'v2', __doc__, __file__, parents=[argparser])
  merchant_id = flags.merchant_id

  try:
    name = 'feed%s' % shopping_common.get_unique_id()
    datafeed = {
        'name': name,
        'contentType': 'products',
        'attributeLanguage': 'en',
        'contentLanguage': 'en',
        'intendedDestinations': ['Shopping'],
        # The file name must be unique per account. We only use unique names in
        # these examples, so it's not an issue here.
        'fileName': name,
        'targetCountry': 'US',
        # You can schedule monthly, weekly or daily.
        #
        # Monthly - set day of month ('dayOfMonth') and hour ('hour')
        # Weekly - set day of week ('weekday') and hour ('hour')
        # Daily - set just the hour ('hour')
        'fetchSchedule': {
            'weekday': 'monday',
            'hour': 6,
            'timeZone': 'America/Los_Angeles',
            'fetchUrl': 'https://feeds.myshop.com/' + name
        },
        'format': {
            'fileEncoding': 'utf-8',
            'columnDelimiter': 'tab',
            'quotingMode': 'value quoting'
        }
    }

    # 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']
    shopping_common.check_mca(config, True)

    name = 'account%s' % shopping_common.get_unique_id()
    account = {'name': name, 'websiteUrl': 'https://%s.example.com/' % name}

    # Add account.
    request = service.accounts().insert(merchantId=merchant_id, body=account)

    result = request.execute()

    print('Created sub-account ID %s for MCA %d.' %
          (result['id'], merchant_id))
def main(argv):
    # Authenticate and construct service.
    service, config, flags = shopping_common.init(argv,
                                                  __doc__,
                                                  parents=[argparser])
    merchant_id = config['merchantId']
    account_id = flags.account_id
    shopping_common.check_mca(config, True)

    new_name = 'updated-account%s' % shopping_common.get_unique_id()
    request = service.accounts().patch(merchantId=merchant_id,
                                       accountId=account_id,
                                       body={'name': new_name})

    result = request.execute()
    print('Account with id %s was updated with new name "%s".' %
          (account_id, result['name']))
def main(argv):
    # Authenticate and construct service.
    service, config, _ = shopping_common.init(argv, __doc__)
    merchant_id = config['merchantId']

    batch = {'entries': []}

    for i in range(BATCH_SIZE):
        offer_id = 'book#%s' % shopping_common.get_unique_id()
        product = product_sample.create_product_sample(
            config,
            offer_id,
            title='This is book number %d' % (i, ),
            price={
                'value': '%d.50' % (i, ),
                'currency': 'USD'
            })
        # Add product to the batch.
        batch['entries'].append({
            'batchId': i,
            'merchantId': merchant_id,
            'method': 'insert',
            'product': product
        })

    try:
        request = service.products().custombatch(body=batch)
        result = request.execute()

        if result['kind'] == 'content#productsCustomBatchResponse':
            entries = result['entries']
            for entry in entries:
                if 'product' in entry:
                    product = entry['product']
                    print(
                        'Product with offerId "%s" and title "%s" was created.'
                        % (product['offerId'], product['title']))
                elif 'errors' in entry:
                    print entry['errors']
        else:
            print 'There was an error. Response: %s' % (result)
    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',
            'product':
            product_sample.create_product_sample(
                config,
                'book#%s' % shopping_common.get_unique_id(),
                title='This is book number %d' % i,
                price={
                    'value': '%d.50' % i,
                    'currency': 'USD',
                }),
        } for i in range(BATCH_SIZE)],
    }

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

    if result['kind'] == 'content#productsCustomBatchResponse':
        entries = result['entries']
        for entry in entries:
            if not shopping_common.json_absent_or_false(entry, 'product'):
                product = entry['product']
                print(
                    'Product "%s" with offerId "%s" and title "%s" was created.'
                    % (product['id'], product['offerId'], product['title']))
            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)
Exemplo n.º 16
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')
Exemplo n.º 17
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')
Exemplo n.º 18
0
def main(argv):
  # Authenticate and construct service.
  service, flags = sample_tools.init(
      argv, 'content', 'v2', __doc__, __file__, parents=[argparser])
  merchant_id = flags.merchant_id

  try:
    offer_id = 'book#%s' % shopping_common.get_unique_id()
    product = {
        'offerId': offer_id,
        'title': 'A Tale of Two Cities',
        'description': 'A classic novel about the French Revolution',
        'link': 'http://my-book-shop.com/tale-of-two-cities.html',
        'imageLink': 'http://my-book-shop.com/tale-of-two-cities.jpg',
        'contentLanguage': CONTENT_LANGUAGE,
        'targetCountry': TARGET_COUNTRY,
        'channel': CHANNEL,
        'availability': 'in stock',
        'condition': 'new',
        'googleProductCategory': 'Media > Books',
        'gtin': '9780007350896',
        'price': {'value': '2.50', 'currency': 'USD'},
        'shipping': [{
            'country': 'US',
            'service': 'Standard shipping',
            'price': {'value': '0.99', 'currency': 'USD'}
        }],
        'shippingWeight': {'value': '200', 'unit': 'grams'}
    }

    # Add product.
    request = service.products().insert(merchantId=merchant_id,
                                        body=product)

    result = request.execute()
    print ('Product with offerId "%s" and title "%s" was created.' %
           (result['offerId'], result['title']))

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

    try:
        offer_id = 'book#%s' % shopping_common.get_unique_id()
        product = product_sample.create_product_sample(config, offer_id)

        # Add product.
        request = service.products().insert(merchantId=merchant_id,
                                            body=product)

        result = request.execute()
        print('Product with offerId "%s" and title "%s" was created.' %
              (result['offerId'], result['title']))

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

    account_names = [
        'account%s' % shopping_common.get_unique_id()
        for i in range(BATCH_SIZE)
    ]
    batch = {
        'entries': [{
            'batchId': i,
            'merchantId': merchant_id,
            'method': 'insert',
            'account': {
                'name': v,
                'websiteUrl': 'https://%s.example.com/' % v,
            },
        } for i, v in enumerate(account_names)],
    }

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

    if result['kind'] == 'content#accountsCustomBatchResponse':
        for entry in result['entries']:
            if not shopping_common.json_absent_or_false(entry, 'account'):
                account = entry['account']
                print('Account %s with name "%s" was created.' %
                      (account['id'], account['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)
def main(argv):
  # Authenticate and construct service.
  service, flags = sample_tools.init(
      argv, 'content', 'v2', __doc__, __file__, parents=[argparser])
  merchant_id = flags.merchant_id

  batch = BatchHttpRequest(callback=product_inserted)

  for i in range(BATCH_SIZE):
    offer_id = 'book#%s' % shopping_common.get_unique_id()
    product = {
        'offerId': offer_id,
        'title': 'This is book number %d' % (i,),
        'description': 'Sample book',
        'link': 'http://my-book-shop.com/book.html',
        'imageLink': 'http://my-book-shop.com/book.jpg',
        'contentLanguage': CONTENT_LANGUAGE,
        'targetCountry': TARGET_COUNTRY,
        'channel': CHANNEL,
        'availability': 'in stock',
        'condition': 'new',
        'googleProductCategory': 'Media > Books',
        'gtin': '9780007350896',
        'price': {'value': '%d.50' % (i,), 'currency': 'USD'},
        'shipping': [{
            'country': 'US',
            'service': 'Standard shipping',
            'price': {'value': '0.99', 'currency': 'USD'}
        }],
        'shippingWeight': {'value': '200', 'unit': 'grams'}
    }
    # Add product to the batch.
    batch.add(service.products().insert(merchantId=merchant_id,
                                        body=product))
  try:
    batch.execute()
  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, flags = sample_tools.init(
      argv, 'content', 'v2', __doc__, __file__, parents=[argparser])
  merchant_id = flags.merchant_id

  batch = BatchHttpRequest(callback=account_inserted)

  for _ in range(BATCH_SIZE):
    name = 'account%s' % shopping_common.get_unique_id()
    account = {
        'name': name,
        'websiteUrl': 'https://%s.example.com/' % (name,)
    }
    # Add account to the batch.
    batch.add(service.accounts().insert(merchantId=merchant_id,
                                        body=account))
  try:
    batch.execute()
  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')
Exemplo n.º 23
0
def main(argv):
    # Authenticate and construct service.
    service, config, _ = shopping_common.init(argv, __doc__)
    merchant_id = config['merchantId']
    shopping_common.check_mca(config, True)

    batch = BatchHttpRequest(callback=account_inserted)

    for _ in range(BATCH_SIZE):
        name = 'account%s' % shopping_common.get_unique_id()
        account = {
            'name': name,
            'websiteUrl': 'https://%s.example.com/' % (name, )
        }
        # Add account to the batch.
        batch.add(service.accounts().insert(merchantId=merchant_id,
                                            body=account))
    try:
        batch.execute()
    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)
Exemplo n.º 25
0
def main(argv):
    # Authenticate and construct service.
    service, flags = sample_tools.init(argv,
                                       'content',
                                       'v2',
                                       __doc__,
                                       __file__,
                                       parents=[argparser])
    merchant_id = flags.merchant_id

    batch = {"entries": []}

    for i in range(BATCH_SIZE):
        offer_id = 'book#%s' % shopping_common.get_unique_id()
        product = {
            'offerId':
            offer_id,
            'title':
            'This is book number %d' % (i, ),
            'description':
            'Sample book',
            'link':
            'http://%s/book.html' % ROOT_URL,
            'imageLink':
            'http://my-book-shop.com/book.jpg',
            'contentLanguage':
            CONTENT_LANGUAGE,
            'targetCountry':
            TARGET_COUNTRY,
            'channel':
            CHANNEL,
            'availability':
            'in stock',
            'condition':
            'new',
            'googleProductCategory':
            'Media > Books',
            'gtin':
            '9780007350896',
            'price': {
                'value': '%d.50' % (i, ),
                'currency': 'USD'
            },
            'shipping': [{
                'country': 'US',
                'service': 'Standard shipping',
                'price': {
                    'value': '0.99',
                    'currency': 'USD'
                }
            }],
            'shippingWeight': {
                'value': '200',
                'unit': 'grams'
            }
        }
        # Add product to the batch.
        batch['entries'].append({
            'batchId': i,
            'merchantId': merchant_id,
            'method': 'insert',
            'product': product
        })

    try:
        request = service.products().custombatch(body=batch)
        result = request.execute()

        if result['kind'] == 'content#productsCustomBatchResponse':
            entries = result['entries']
            for entry in entries:
                if 'product' in entry:
                    product = entry['product']
                    print(
                        'Product with offerId "%s" and title "%s" was created.'
                        % (product['offerId'], product['title']))
                elif 'errors' in entry:
                    print entry['errors']
        else:
            print 'There was an error. Response: %s' % (result)
    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, flags = sample_tools.init(argv,
                                       'content',
                                       'v2',
                                       __doc__,
                                       __file__,
                                       parents=[argparser])
    merchant_id = flags.merchant_id

    batch = BatchHttpRequest(callback=product_inserted)

    for i in range(BATCH_SIZE):
        offer_id = 'book#%s' % shopping_common.get_unique_id()
        product = {
            'offerId':
            offer_id,
            'title':
            'This is book number %d' % (i, ),
            'description':
            'Sample book',
            'link':
            'http://my-book-shop.com/book.html',
            'imageLink':
            'http://my-book-shop.com/book.jpg',
            'contentLanguage':
            CONTENT_LANGUAGE,
            'targetCountry':
            TARGET_COUNTRY,
            'channel':
            CHANNEL,
            'availability':
            'in stock',
            'condition':
            'new',
            'googleProductCategory':
            'Media > Books',
            'gtin':
            '9780007350896',
            'price': {
                'value': '%d.50' % (i, ),
                'currency': 'USD'
            },
            'shipping': [{
                'country': 'US',
                'service': 'Standard shipping',
                'price': {
                    'value': '0.99',
                    'currency': 'USD'
                }
            }],
            'shippingWeight': {
                'value': '200',
                'unit': 'grams'
            }
        }
        # Add product to the batch.
        batch.add(service.products().insert(merchantId=merchant_id,
                                            body=product))
    try:
        batch.execute()
    except client.AccessTokenRefreshError:
        print(
            'The credentials have been revoked or expired, please re-run the '
            'application to re-authorize')