def update_product_item_by_retailer_id(self, catalog_id, retailer_id, params): """ Update product item specified by retailer_id and catalog_id """ catalog = ProductCatalog(catalog_id) result = catalog.update_product(retailer_id, **params) return result
def create_product_catalog(params=None): if params is None: params = {} if 'name' not in params: params['name'] = unique_name('Test Catalog ') product_catalog = ProductCatalog(None, test_config.business_id) product_catalog.update(params) product_catalog.remote_create() return product_catalog
def get_products_by_product_catalog_id(self, product_catalog_id, params=None): """ Retrieves products that belong to the specified product feed. """ catalog = ProductCatalog(product_catalog_id) fields = [ 'availability', 'brand', 'category', 'condition', 'description', 'id', 'image_url', 'name', 'price', 'retailer_id', 'url' ] result = catalog.get_products(fields, params) return result
def check_product_images( self, catalog_id, limit ): """ Check the first "limit" products of a product catalog """ catalog = ProductCatalog(catalog_id) fields = [ 'additional_image_urls', 'image_url', 'url' ] products = catalog.get_products(fields) image_ok_count = 0 additional_image_ok_count = 0 total_count = 0 small_images = [] for product in products: total_count += 1 if total_count > limit: total_count -= 1 break if self.is_size_ok(product['image_url']): image_ok_count += 1 else: if len(small_images) < 5: small_images.append(( product['url'], self.extract_from_safe_img(product['image_url']) )) if 'additional_image_urls' in product.keys() and \ product['additional_image_urls']: image_urls = product['additional_image_urls'] for url in image_urls: if self.is_size_ok(url): additional_image_ok_count += 1 break res = (total_count, image_ok_count, additional_image_ok_count, small_images) return res
config_file = open(config_filename) config = json.load(config_file) config_file.close() from facebookads.api import FacebookAdsApi from facebookads.objects import ProductCatalog, Product FacebookAdsApi.init( config['app_id'], config['app_secret'], config['access_token'], ) if __name__ == '__main__': catalog_id = '<INSERT_YOUR_CATALOG_ID_HERE>' catalog = ProductCatalog(catalog_id) items = [] for line in sys.stdin.readlines(): if line.endswith('\n'): items.append(line[:-1].split(',')) else: items.append(line.split(',')) for item in items: product_id, new_price = item if new_price == '-': response = catalog.update_product( product_id, availability=Product.Availability.out_of_stock )
config_file = open(config_filename) config = json.load(config_file) config_file.close() from facebookads.api import FacebookAdsApi from facebookads.objects import ProductCatalog, Product FacebookAdsApi.init( config['app_id'], config['app_secret'], config['access_token'], ) if __name__ == '__main__': catalog_id = '<INSERT_YOUR_CATALOG_ID_HERE>' catalog = ProductCatalog(catalog_id) fields = [ Product.Field.id, Product.Field.name, Product.Field.price, Product.Field.url, Product.Field.availability ] """ get products cost more than $99.99. """ params = { 'filter': { 'price_amount': {'gt': '9999'} } }
# You are hereby granted a non-exclusive, worldwide, royalty-free license to # use, copy, modify, and distribute this software in source code or binary # form for use in connection with the web services and APIs provided by # Facebook. # As with any software that integrates with the Facebook platform, your use # of this software is subject to the Facebook Developer Principles and # Policies [http://developers.facebook.com/policy/]. This copyright notice # shall be included in all copies or substantial portions of the software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. from examples.docs import fixtures product_catalog_id = fixtures.create_product_catalog().get_id() # _DOC oncall [pruno] # _DOC open [PRODUCTCATALOG_GET_EXTERNAL_EVENT_SOURCES] # _DOC vars [product_catalog_id] from facebookads.objects import ProductCatalog product_catalog = ProductCatalog(product_catalog_id) product_catalog.get_external_event_sources() # _DOC close [PRODUCTCATALOG_GET_EXTERNAL_EVENT_SOURCES]
import sys sys.path.insert(1, os.path.join(this_dir, os.pardir, os.pardir)) config_file = open(config_filename) config = json.load(config_file) config_file.close() from facebookads.api import FacebookAdsApi from facebookads.objects import ProductCatalog, Product FacebookAdsApi.init( config['app_id'], config['app_secret'], config['access_token'], ) if __name__ == '__main__': catalog_id = '<INSERT_YOUR_CATALOG_ID_HERE>' catalog = ProductCatalog(catalog_id) fields = [ Product.Field.id, Product.Field.name, Product.Field.price, Product.Field.url, Product.Field.availability ] """ get products cost more than $99.99. """ params = {'filter': {'price_amount': {'gt': '9999'}}} results = catalog.get_products(fields, params) print(results)
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. from facebookads import test_config from examples.docs import fixtures from facebookads.objects import ProductCatalog product_catalog_id = fixtures.create_product_catalog().get_id() pixel_id = fixtures.create_ads_pixel().get_id() app_id = test_config.app_id product_catalog = ProductCatalog(product_catalog_id) product_catalog.add_external_event_sources([ pixel_id, app_id, ]) # _DOC oncall [pruno] # _DOC open [PRODUCTCATALOG_REMOVE_EXTERNAL_EVENT_SOURCES] # _DOC vars [product_catalog_id, pixel_id, app_id] from facebookads.objects import ProductCatalog product_catalog = ProductCatalog(product_catalog_id) product_catalog.remove_external_event_sources([ pixel_id, app_id, ])
config_file = open(config_filename) config = json.load(config_file) config_file.close() from facebookads.api import FacebookAdsApi from facebookads.objects import ProductCatalog, Product FacebookAdsApi.init( config['app_id'], config['app_secret'], config['access_token'], ) if __name__ == '__main__': catalog_id = '<INSERT_YOUR_CATALOG_ID_HERE>' catalog = ProductCatalog(catalog_id) items = [] for line in sys.stdin.readlines(): if line.endswith('\n'): items.append(line[:-1].split(',')) else: items.append(line.split(',')) for item in items: product_id, new_price = item if new_price == '-': response = catalog.update_product( product_id, availability=Product.Availability.out_of_stock) print('Product {} is now out of stock'.format(product_id)) else:
# As with any software that integrates with the Facebook platform, your use # of this software is subject to the Facebook Developer Principles and # Policies [http://developers.facebook.com/policy/]. This copyright notice # shall be included in all copies or substantial portions of the software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. from facebookads import test_config business_id = test_config.business_id # _DOC open [PRODUCTCATALOG_CREATE] # _DOC vars [business_id] from facebookads.objects import ProductCatalog product_catalog = ProductCatalog(parent_id=business_id) product_catalog[ProductCatalog.Field.name] = 'Catalog' product_catalog.remote_create() # _DOC close [PRODUCTCATALOG_CREATE] product_catalog.remote_delete()