0

我试图使用来自 facebook 业务 SDK API 的 Targetting search API。

ImportError:没有名为 facebookads.adobjects.targetingsearch 的模块

使用 Python 2.7.12 ~

试图执行这段代码:

from facebookads.adobjects.targetingsearch import TargetingSearch
params = {
'q': 'un',
'type': 'adgeolocation',
'location_types': ['country'],
}

resp = TargetingSearch.search(params=params)
print(resp)

实际结果 :

Traceback (most recent call last):
File "test.py", line 2, in <module>
from facebookads.adobjects.targetingsearch import TargetingSearch
ImportError: No module named facebookads.adobjects.targetingsearch
4

1 回答 1

0

Facebook Marketing API 文档有点过时。您应该从以下位置替换导入:

from facebookads.adobjects.targetingsearch import TargetingSearch

至:

from facebook_business.adobjects.targetingsearch import TargetingSearch

此外,在请求定位数据之前,您应该使用生成的访问令牌初始化 FacebookAdsApi:

from facebook_business.api import FacebookAdsApi

FacebookAdsApi.init(access_token=access_token)
于 2019-11-06T00:25:20.847 回答