0
我試圖從我的Facebook商業廣告帳戶中使用Python中的Facebook營銷API包獲取特定廣告系列的名稱。我只想選擇與某個特定名稱相匹配的廣告系列,但我只會列出最近創建的25個廣告系列。我如何在Python中執行此操作?如何使用Python從Facebook Marketing API中按名稱獲取特定廣告系列?
我一直沒能找到任何正確的語法在「get_campaigns」命令中的「params」參數的例子。我想,如果我想只選擇名爲「運動-X」和「運動-Y」它可能是這個樣子,如果我能在詞典匹配2個值1個關鍵的活動:
from facebookads.api import FacebookAdsApi
from facebookads.adobjects.campaign import Campaign
app_id = 'xxxxx'
app_secret = 'xxxxx'
access_token = 'xxxxx'
FacebookAdsApi.init(app_id, app_secret, access_token)
account = AdAccount('act_xxxxxxxxx')
account.get_campaigns(fields=[Campaign.Field.name], params={'name': ['Campaign-X', 'Campaign-Y']})
我能夠在Facebook的開發者網站上的Graph API Explorer中工作,但是我很難將其翻譯成Python。當我做'account.get_campaigns(fields = [Campaign.Field.name],filtering = [{'field':'campaign.name','operator':'CONTAIN','value':'Campaign X'}] )'它說'TypeError:get_campaigns()得到了一個意外的關鍵字參數'filtering'' 這就是我在API Explorer中的工作正常: 'act_XXXXXXXXX/campaigns?fields = name&filtering = [{'field' :'name','operator':'EQUAL','value':'Campaign X'}]' – Jazziwicz
您需要在'params'中包含這樣的內容: 'account.get_campaigns'(fields = [Campaign.Field.name],params = ['filtering':[{'field':'campaign.name','operator':'CONTAIN','va lue':'Campaign X'}]])'' –