-
-
Save clemfromspace/35175d98aeaf246d99a92998f0ab7c54 to your computer and use it in GitHub Desktop.
Instagram and Facebook ads with Algolia Recommend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
facebook_api_version = 'v14.0' | |
facebook_catalog_id = '<facebook-catalog-id>' | |
facebook_api_token = '<facebook-api-token>' | |
res = requests.post( | |
f'https://graph.facebook.com/{api_version}/{product_catalog_id}/product_sets', | |
json={ | |
'access_token': facebook_api_token, | |
'name': 'Trending products', | |
'filter': { | |
'retailer_id': { | |
'is_any': trending_product_skus | |
} | |
} | |
} | |
) | |
trending_product_set_id = res.json()['id'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from algoliasearch.recommend_client import RecommendClient | |
algolia_app_id = '<algolia-app-id>' | |
algolia_api_key = '<algolia-api-key>' | |
algolia_index_name = '<algolia-index-name>' | |
recommend_client = RecommendClient.create(app_id, api_key) | |
recommendations = recommend_client.get_recommendations( | |
queries=[ | |
{ | |
'indexName': algolia_index_name, | |
'model': 'trending-items', | |
} | |
] | |
) | |
trending_product_skus = [product['sku'] for product in recommendations['results'][0]['hits']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
facebook_api_version = 'v14.0' | |
facebook_api_token = '<facebook-api-token>' | |
# The `product_set_id` is obtained during the creation of the product set, refer to the `create_product_set.py` file. | |
facebook_product_set_id = '' | |
# Refer to the `fetch_trending_product_skus.py` file for fetching the trending products. | |
trending_products = [] | |
requests.post( | |
f'https://graph.facebook.com/{version}/{product_set_id}/', | |
json={ | |
'access_token': facebook_api_token, | |
'filter': { | |
"retailer_id": { | |
"is_any": [product['sku'] for product in trending_products] | |
} | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment