You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Instagram Graph API目录搜索精准匹配产品名称

解决Instagram Graph API产品名称完全匹配搜索问题
  • 问题本质:catalog_product_search接口的q参数仅支持模糊匹配,会返回所有包含目标关键词的产品,无法直接通过接口参数实现完全匹配。

  • 实现完全匹配的方法:
    先通过原有接口获取模糊搜索结果,再在本地对返回数据进行过滤,只保留名称与目标字符串完全一致的产品。

修改后的代码示例:

import requests

endpointParams = dict()
endpointParams['access_token'] = params['access_token']
endpointParams['q'] = 'fimo necklace'
url='https://graph.facebook.com/v14.0/{instagram_account_id}/catalog_product_search?catalog_id=12345'
response = requests.get(url, params=endpointParams)
data = response.json()

# 过滤出名称完全匹配的产品
exact_match_products = [
    item for item in data.get('data', [])
    if item.get('name') == 'fimo necklace'
]

# 处理分页场景(如果结果有多页)
next_page = data.get('paging', {}).get('next')
while next_page:
    response = requests.get(next_page)
    page_data = response.json()
    exact_match_products.extend([
        item for item in page_data.get('data', [])
        if item.get('name') == 'fimo necklace'
    ])
    next_page = page_data.get('paging', {}).get('next')

print(exact_match_products)

注:如果你的产品名称存在大小写差异,可将判断条件改为item.get('name').lower() == 'fimo necklace'.lower()来忽略大小写匹配。

内容的提问来源于stack exchange,提问作者Bushmaster

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 23:20:28