Facebook 业务 API 通过 python 请求活动

Facebook Business API request campaigns via python

我们正忙于将 Facebook 的营销 API 升级到业务 API(不是图表 API 也不是营销 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_'

None 的 ID 以 act_ 开头,我目前使用的是应用程序仪表板左上角的应用程序 ID,我应该使用哪个应用程序 ID? Marketing API

业务管理器中的广告账号在前台登录界面获取

From Business Manager