1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# 4# Copyright 2014 Google Inc. All Rights Reserved. 5 6"""Query with grouping against the shopping search API""" 7 8import pprint 9 10from googleapiclient.discovery import build 11 12 13SHOPPING_API_VERSION = 'v1' 14DEVELOPER_KEY = 'AIzaSyACZJW4JwcWwz5taR2gjIMNQrtgDLfILPc' 15 16 17def main(): 18 """Get and print a feed of public products in the United States mathing a 19 text search query for 'digital camera' and grouped by the 8 top brands. 20 21 The list method of the resource should be called with the "crowdBy" 22 parameter. Each parameter should be designed as <attribute>:<occurence>, 23 where <occurrence> is the number of that <attribute> that will be used. For 24 example, to crowd by the 5 top brands, the parameter would be "brand:5". The 25 possible rules for crowding are currently: 26 27 account_id:<occurrence> (eg account_id:5) 28 brand:<occurrence> (eg brand:5) 29 condition:<occurrence> (eg condition:3) 30 gtin:<occurrence> (eg gtin:10) 31 price:<occurrence> (eg price:10) 32 33 Multiple crowding rules should be specified by separating them with a comma, 34 for example to crowd by the top 5 brands and then condition of those items, 35 the parameter should be crowdBy="brand:5,condition:3" 36 """ 37 client = build('shopping', SHOPPING_API_VERSION, developerKey=DEVELOPER_KEY) 38 resource = client.products() 39 # The crowdBy parameter to the list method causes the results to be grouped, 40 # in this case by the top 8 brands. 41 request = resource.list(source='public', country='US', q=u'digital camera', 42 crowdBy='brand:8') 43 response = request.execute() 44 pprint.pprint(response) 45 46 47if __name__ == '__main__': 48 main() 49