我们正忙于从Marketing API升级到Facebook的Business API(不是图谱API和不是Marketing API)。该文档指出,应该可以使用以下代码创建一个test.py:
import sys
sys.path.append('/opt/homebrew/lib/python2.7/site-packages')
sys.path.append('/opt/homebrew/lib/python2.7/site-packages/facebook_business-3.0.0-py2.7.egg-info')
from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
my_app_id = 'your-app-id'
my_app_secret = 'your-appsecret'
my_access_token = 'your-access-token'
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
my_account = AdAccount('your-adaccount-id')
campaigns = my_account.get_campaigns()
print(campaigns)
这需要我通过以下哈希获得的应用程序秘密证明:
facebook_app_id = 'xxxxx'
facebook_app_secret = 'xxxxx'
facebook_app_token = 'xxxxx|xxxxx'.format(facebook_app_id,facebook_app_secret)
import hmac,hashlib
app_secret_proof = hmac.new(facebook_app_secret.encode('utf-8'),
msg=facebook_app_token.encode('utf-8'),
digestmod=hashlib.sha256).hexdigest()
print(app_secret_proof)
这是我得到的错误:
Traceback (most recent call last):
File "test.py", line 12, in <module>
FacebookAdsApi.init(my_app_id,my_app_secret,my_access_token,my_appsecret_proof)
File "/Users/facebook_business/api.py", line 202, in init
cls.set_default_account_id(account_id)
File "/Users/facebook_business/api.py", line 225, in set_default_account_id
"Account ID provided in FacebookAdsApi.set_default_account_id "
ValueError: Account ID provided in FacebookAdsApi.set_default_account_id expects a string that begins with 'act_'
该ID都不以act_开头,我目前正在使用应用仪表板左上方的应用ID,该使用哪一个? Marketing API