如何通过Meta Marketing API获取商品start_date及最后编辑日期字段
解决方案
1. 字段澄清与替换
- 你要的商品创建日期并非
start_date(该字段是商品的上线生效日期,手动创建商品时若未主动设置则返回空值),应使用系统自动记录的created_time字段。 - 最后编辑日期对应API中的
updated_time字段,该字段由系统自动维护,商品每次编辑后都会更新。
2. 修改代码获取目标字段
更新请求参数中的fields列表,加入created_time和updated_time即可获取所需日期:
import requests def fetch_products_from_catalog(access_token: str, catalog_id: str): try: print('Fetching products for catalog id: ', catalog_id) url = f"https://graph.facebook.com/v22.0/{catalog_id}/products" params = { "access_token": access_token, "fields": "id,retailer_id,name,price,sale_price,category,created_time,updated_time" } products = [] while url: response = requests.get(url, params=params) response.raise_for_status() data = response.json() products.extend(data.get("data", [])) url = data.get("paging", {}).get("next") params = {} # Only needed for the first request print('Products: ', products) return products except Exception as e: raise Exception(f"Error fetching products from catalog: {e}")
3. 异常情况排查
- 权限验证:确认你的
access_token拥有catalog_management或business_management权限,且已正确关联目标商品目录。 start_date字段补充:如果确实需要获取start_date,需在Commerce Manager手动为商品配置该字段,或通过商品Feed批量导入时明确设置该值,API才会返回对应内容。
内容的提问来源于stack exchange,提问作者adrCoder
相关产品推荐
相关产品推荐

