我试图使用来自Facebook商业SDK API的Targeting搜索API。
ImportError:没有名为facebookads.adobjects.targetingsearch的模块
使用Python 2.7.12 〜
正在尝试执行这段代码:
var scrollableDiv= document.getElementsByClassName('scroll')[0],
width = parseInt(scrollableDiv.offsetWidth, 10),
cldWidth = parseInt(scrollableDiv.children[0].offsetWidth, 10),
distance = cldWidth - width,
speed = 50,
current = 0;
scrollableDiv.children[0].style.left = current + "px";
var scrollFunction = function (e) {
e = window.event || e;
var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
if ((delta == -1 && current * speed >= -distance) || (delta == 1 && current * speed < 0)) {
current = current + delta;
}
scrollableDiv.children[0].style.left = (current * speed) + 'px';
e.preventDefault();
};
if (scrollableDiv.addEventListener) {
scrollableDiv.addEventListener("mousewheel", scrollFunction, false);
scrollableDiv.addEventListener("DOMMouseScroll", scrollFunction, false);
} else {
scrollableDiv.attachEvent("onmousewheel", scrollFunction);
}
$('#right-button').click(function () {
event.preventDefault();
$('.gallery-scroll').animate({
scrollLeft: "+=800px"
}, 500);
$('#left-button').click(function () {
event.preventDefault();
$('.gallery-scroll').animate({
scrollLeft: "-=800px"
}, 500);
});
});
实际结果:
from facebookads.adobjects.targetingsearch import TargetingSearch
params = {
'q': 'un',
'type': 'adgeolocation',
'location_types': ['country'],
}
resp = TargetingSearch.search(params=params)
print(resp)
答案 0 :(得分: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)