Facebook python marketing API AttributeError

时光总嘲笑我的痴心妄想 提交于 2019-12-08 02:14:43

问题


I am trying to use Facebook Marketing API through its python package facebookapi.

here's a code snippet:

from facebookads.adobjects.customaudience import CustomAudience

audience = CustomAudience(parent_id='act_10336...')
audience[CustomAudience.Field.subtype] = CustomAudience.Subtype.custom
audience[CustomAudience.Field.name] = 'My new CA'
audience[CustomAudience.Field.description] = 'People who bought on my website'

audience.remote_create()

It is taken directly from Facebook's example for custom audience creation given here.

I put the appropriate AD_ACCOUNT_ID in the second line.

I get an error:

AttributeError: 'NoneType' object has no attribute 'call'

After much investigation I found that this line from api.py returns None, which I think is at the heart of the problem:

FacebookAdsApi.get_default_api()

In fact, any api call I tried to perform returned a similar error.

Anyone knows anything about that?


回答1:


You didn't bootstrap the API? Try this:

from facebookads.api import FacebookAdsApi
from facebookads import objects

my_app_id = '<APP_ID>'
my_app_secret = '<APP_SECRET>'
my_access_token = '<ACCESS_TOKEN>'
proxies = {'http': '<HTTP_PROXY>', 'https': '<HTTPS_PROXY>'} # add proxies if needed
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token, proxies)


来源:https://stackoverflow.com/questions/40361101/facebook-python-marketing-api-attributeerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!