Skip to content

Instantly share code, notes, and snippets.

@hamletbatista
Created April 27, 2019 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hamletbatista/96ab561758668a696b67939e221e8653 to your computer and use it in GitHub Desktop.
Save hamletbatista/96ab561758668a696b67939e221e8653 to your computer and use it in GitHub Desktop.
MAX_PAGE_SIZE = 10
MAX_RESULT = 20
merchant_id = XXXXXXX
#execute list API
request = service.products().list(
merchantId=merchant_id, maxResults=MAX_PAGE_SIZE)
#iterate over results and stop at MAX_RESULT products
count = MAX_RESULT
while request is not None and count > 0:
result = request.execute()
products = result.get('resources')
if not products:
print('No products were found.')
break
for product in products:
print('Product "%s" with title "%s" was found.' %
(product['id'], product['title']))
count = count -1
if count == 0:
break
request = service.products().list_next(request, result)
#example output
#Product "online:en:US:XX-XXXXX-XX" with title "Produc Title 1" was found.
#Product "online:en:US:XX-XXX-XX-XX" with title "Produc Title 2" was found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment