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 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 api_create(self, parent_id, fields=None, params=None, batch=None, pending=False): from facebook_business.adobjects.productcatalog import ProductCatalog return ProductCatalog(api=self._api, fbid=parent_id).create_category( fields, params, batch, pending)
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
def api_create(self, parent_id, fields=None, params=None, batch=None, success=None, failure=None, pending=False): from facebook_business.adobjects.productcatalog import ProductCatalog return ProductCatalog(api=self._api, fbid=parent_id).create_automotive_model( fields, params, batch, success, failure, pending)
def get_product_catalog(self, access_token, catalog_id): """Get product catalog object Args: access_token (str): any kind of access token whicc has permissions catalog_id (str): catalog id Returns: obj: ProductCatalog object """ FacebookAdsApi.init(app_id=self.__app_id, app_secret=self.__app_secret, access_token=access_token) return ProductCatalog(fbid=catalog_id)
# 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 facebook_business.adobjects.productcatalog import ProductCatalog from facebook_business.adobjects.productset import ProductSet from facebook_business.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<PRODUCT_CATALOG_ID>' FacebookAdsApi.init(access_token=access_token) fields = [ ] params = { 'name': 'Test Set', 'filter': {'product_type':{'i_contains':'shirt'}}, } print ProductCatalog(id).create_product_set( fields=fields, params=params, )
# 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 facebook_business.adobjects.productcatalog import ProductCatalog from facebook_business.adobjects.producteventstat import ProductEventStat from facebook_business.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<PRODUCT_CATALOG_ID>' FacebookAdsApi.init(access_token=access_token) fields = [] params = {} print ProductCatalog(id).get_event_stats( fields=fields, params=params, )
# 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 facebook_business.adobjects.productcatalog import ProductCatalog from facebook_business.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<PRODUCT_CATALOG_ID>' FacebookAdsApi.init(access_token=access_token) fields = [] params = { 'hotel_catalog_settings': { 'pull_config_id': '<pullConfigID>' }, } print ProductCatalog(id).update( fields=fields, params=params, )
config = json.load(config_file) config_file.close() from facebook_business.api import FacebookAdsApi from facebook_business.adobjects.productcatalog import ProductCatalog from facebook_business.adobjects.productitem import ProductItem 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=ProductItem.Availability.out_of_stock )
'image_url': 'https://www.example.com/pic1.jpg', 'tags': ['front view', 'balcony'] }, { 'image_url': 'http://www.example.com/pic2.jpg', 'tags': ['lobby view'] }], 'address': { 'street_address': '1 Hacker Way', 'city': 'Menlo Park', 'region': 'California', 'country': 'United States', 'postal_code': '94025', 'neighborhoods': ['Palo Alto', 'Menlo Park'], 'latitude': 37.484116, 'longitude': -122.148244 }, 'guest_ratings': [{ 'score': 7.8, 'max_score': 10, 'rating_system': 'sample_rating', 'number_of_raters': 780 }], 'star_rating': '4', 'phone': '+351234123456', } print ProductCatalog(id).create_hotel( fields=fields, params=params, )
config = json.load(config_file) config_file.close() from facebook_business.api import FacebookAdsApi from facebook_business.adobjects.productcatalog import ProductCatalog from facebook_business.adobjects.productitem import ProductItem 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 = [ ProductItem.Field.id, ProductItem.Field.name, ProductItem.Field.price, ProductItem.Field.url, ProductItem.Field.availability ] """ get products cost more than $99.99. """ params = { 'filter': { 'price_amount': {'gt': '9999'} } }