1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# 4# Copyright 2014 Google Inc. All Rights Reserved. 5 6"""Query with ranked results 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' ranked by ascending price. 20 21 The list method for the resource should be called with the "rankBy" 22 parameter. 5 parameters to rankBy are currently supported by the API. They 23 are: 24 25 "relevancy" 26 "modificationTime:ascending" 27 "modificationTime:descending" 28 "price:ascending" 29 "price:descending" 30 31 These parameters can be combined 32 33 The default ranking is "relevancy" if the rankBy parameter is omitted. 34 """ 35 client = build('shopping', SHOPPING_API_VERSION, developerKey=DEVELOPER_KEY) 36 resource = client.products() 37 # The rankBy parameter to the list method causes results to be ranked, in 38 # this case by ascending price. 39 request = resource.list(source='public', country='US', q=u'digital camera', 40 rankBy='price:ascending') 41 response = request.execute() 42 pprint.pprint(response) 43 44 45if __name__ == '__main__': 46 main() 47