用facebook营销api python sdk创建第一个广告系列

时间:2016-10-05 17:19:36

标签: facebook-graph-api facebook-marketing-api

我想用python学习facebook marketing api,我想用它创建我的第一个facebook活动。

所以我输入了python shell:

from facebookads.api import FacebookAdsApi
from facebookads import objects

my_app_id = '<APP_ID>'
my_app_secret = '<APP_SECRET>'
my_access_token = '<ACCESS_TOKEN>'
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)


from facebookads.adobjects.campaign import Campaign

campaign = Campaign(parent_id='act_<AD_ACCOUNT_ID>')
campaign.update({
    Campaign.Field.name: 'My First Campaign',
    Campaign.Field.objective: '<LINK_CLICKS>',
})

campaign.remote_create(params={
    'status': Campaign.Status.paused,
})
print(campaign)

我在哪里发布: <APP_ID>我的APP ID <APP_SECRET>我的app秘密 我为ad_management创建了令牌<ACCESS_TOKEN> <AD_ACCOUNT_ID>我的添加帐户ID

但我有错误......

Warning (from warnings module):
  File "C:\Users\G\AppData\Local\Programs\Python\Python35-32\lib\site-packages\facebookads\utils\api_utils.py", line 30
    warnings.warn(message)
UserWarning: value of objective might not be compatible.  Expect objective_enum;  got <class 'str'>
Traceback (most recent call last):
  File "C:/Users/G/AppData/Local/Programs/Python/Python35-32/fb-api-test.py", line 18, in <module>
    'status': Campaign.Status.paused,
  File "C:\Users\G\AppData\Local\Programs\Python\Python35-32\lib\site-packages\facebookads\adobjects\abstractcrudobject.py", line 290, in remote_create
    response = request.execute()
  File "C:\Users\G\AppData\Local\Programs\Python\Python35-32\lib\site-packages\facebookads\api.py", line 658, in execute
    api_version=self._api_version,
  File "C:\Users\G\AppData\Local\Programs\Python\Python35-32\lib\site-packages\facebookads\api.py", line 325, in call
    raise fb_response.error()
facebookads.exceptions.FacebookRequestError: 

  Message: Call was not successful
  Method:  POST
  Path:    https://graph.facebook.com/v2.7/act_<ad_account_id>/campaigns
  Params:  {'status': 'PAUSED', 'objective': '<LINK_CLICKS>', 'name': 'My First Campaign'}

  Status:  400
  Response:
    {
      "error": {
        "message": "Invalid OAuth access token.",
        "type": "OAuthException",
        "fbtrace_id": "E...",
        "code": 190
      }
    }

我还应该做些什么才能让它发挥作用?

1 个答案:

答案 0 :(得分:0)

您可以按照此页面生成访问令牌,尤其是通过图形api资源管理器: https://developers.facebook.com/docs/marketing-api/access#manually-getting-access-tokens

您还应将目标更改为以下其中一项: APP_INSTALLS,BRAND_AWARENESS,CONVERSIONS,EVENT_RESPONSES,LEAD_GENERATION,LINK_CLICKS,LOCAL_AWARENESS,OFFER_CLAIMS,PAGE_LIKES,POST_ENGAGEMENT,PRODUCT_CATALOG_SALES,REACH,VIDEO_VIEWS