我使用 pipenv 安装 facebookads,但在解析 AdUser 模块时遇到了问题。
import facebookads
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adsinsights import AdsInsights
from facebookads.api import FacebookAdsApi
from facebookads import adobjects
from facebookads.adobjects import AdUser
access_token = 'removed from code sample'
ad_account_id = 'removed from code sample'
app_secret = 'removed from code sample'
app_id = 'removed from code sample'
FacebookAdsApi.init(app_id, app_secret, access_token)
# Add after FacebookAdsApi.init
me = AdUser(fbid='me')
my_account = me.get_ad_accounts()[0]
print(my_account)
Pycharm 显示错误:未解决的参考:'AdUser'
控制台显示以下内容:
Traceback (most recent call last):
File "F:/cp/python-scripts/tests-facebook.py", line 11, in <module>
from facebookads.adobjects import AdUser
ImportError: cannot import name 'AdUser'
我已经尝试卸载并重新安装 facebookads SDK。它没有帮助。
另一位开发人员建议虚拟环境可能存在问题。
任何有关如何解决此问题的见解都会有所帮助,谢谢。