首页 > 解决方案 > 使用 Facebook Python Business SDK 使用 remote_create 时出现 TypeError

问题描述

尝试在 Facebook Python Business SDK 中运行 remote_create 方法时,我目前收到此错误(以及最近的调用):

    Traceback (most recent call last):
  File "ad_creator.py", line 41, in <module>
campaign.remote_create()
  File "/usr/local/lib/python3.6/site-packages/facebook_business/adobjects/abstractcrudobject.py", line 296, in remote_create
response = request.execute()
  File "/usr/local/lib/python3.6/site-packages/facebook_business/api.py", line 667, in execute
api_version=self._api_version,
  File "/usr/local/lib/python3.6/site-packages/facebook_business/api.py", line 329, in call
if fb_response.is_failure():
  File "/usr/local/lib/python3.6/site-packages/facebook_business/api.py", line 117, in is_failure
return not self.is_success()
  File "/usr/local/lib/python3.6/site-packages/facebook_business/api.py", line 102, in is_success
    return json_body['success']
TypeError: string indices must be integers

看来错误是从 API 中的 api.py 文件引发的: https ://github.com/facebook/facebook-python-business-sdk/blob/master/facebook_business/api.py

我的代码(创建 Facebook 会话后)如下:

if __name__ == '__main__':
    FacebookAdsApi.set_default_api(api)

    account = AdAccount(config['act_id'])

    print('**** Creating ad...')

    campaign = Campaign(parent_id=account)
    campaign.update({
        Campaign.Field.name: 'My First Campaign',
        Campaign.Field.objective: 'REACH',
    })

    campaign.remote_create()

    print(campaign)

请帮助我找出导致 TypeError 的原因。

标签: pythonfacebook

解决方案


推荐阅读