1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# 4# Copyright 2014 Google Inc. All Rights Reserved. 5 6"""Query that is restricted by a parameter against the public shopping search 7API""" 8 9import pprint 10 11from googleapiclient.discovery import build 12 13 14SHOPPING_API_VERSION = 'v1' 15DEVELOPER_KEY = 'AIzaSyACZJW4JwcWwz5taR2gjIMNQrtgDLfILPc' 16 17 18def main(): 19 """Get and print a feed of all public products matching the search query 20 "digital camera", that are created by "Canon" available in the 21 United States. 22 23 The "restrictBy" parameter controls which types of results are returned. 24 25 Multiple values for a single restrictBy can be separated by the "|" operator, 26 so to look for all products created by Canon, Sony, or Apple: 27 28 restrictBy = 'brand:canon|sony|apple' 29 30 Multiple restricting parameters should be separated by a comma, so for 31 products created by Sony with the word "32GB" in the title: 32 33 restrictBy = 'brand:sony,title:32GB' 34 """ 35 client = build('shopping', SHOPPING_API_VERSION, developerKey=DEVELOPER_KEY) 36 resource = client.products() 37 request = resource.list(source='public', country='US', 38 restrictBy='brand:canon', q='Digital Camera') 39 response = request.execute() 40 pprint.pprint(response) 41 42 43if __name__ == '__main__': 44 main() 45