facebook / facebook-python-business-sdk

Python SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
1.32k stars 644 forks source link

'TypeError: string indices must be integers' when getting AdCreatives #642

Closed SoochangChung closed 1 year ago

SoochangChung commented 1 year ago

Hello, I'm having the following issue when I try to get AdCreative data with the python SDK. I tried reporting it as a bug on Facebook, but they replied saying that python SDK issues are handled in the GItHub repo issues. Here is the traceback error message

  ad_creative_req.execute()]:
  File "/home/airflow/.local/lib/python3.8/site-packages/facebook_business/api.py", line 789, in __next__
    if not self._queue and not self.load_next_page():
  File "/home/airflow/.local/lib/python3.8/site-packages/facebook_business/api.py", line 866, in load_next_page
    self._queue = self.build_objects_from_response(response)
  File "/home/airflow/.local/lib/python3.8/site-packages/facebook_business/api.py", line 875, in build_objects_from_response
    return self._object_parser.parse_multiple(response)
  File "/home/airflow/.local/lib/python3.8/site-packages/facebook_business/adobjects/objectparser.py", line 95, in parse_multiple
    ret = [AbstractObject.create_object(self._api, data,
  File "/home/airflow/.local/lib/python3.8/site-packages/facebook_business/adobjects/abstractobject.py", line 173, in create_object
    new_object._set_data(data)
  File "/home/airflow/.local/lib/python3.8/site-packages/facebook_business/adobjects/abstractcrudobject.py", line 192, in _set_data
    self[key] = data[key]
TypeError: string indices must be integers

and this is the part of the code block getting the data

from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.adcreative import AdCreative
from facebook_business.api import FacebookAdsApi

api = FacebookAdsApi.init(access_token=facebook_conn.password,
                              timeout=10000)

ad_creative_batch = api.new_batch()
ad_creative_req_list = []

    for fb_account in AD_ACCOUNTS[app_name].values():
        account = AdAccount(f'act_{fb_account.id}')
        ad_creative_req_list.append(account.get_ad_creatives(
            fields=ad_creative_target_fields,
            params={
                'thumbnail_width': 150,
                'thumbnail_height': 120,
                'limit': 15,
            },
            batch=ad_creative_batch),
        )

    with TempFileContext() as tmp_ctx:
        with gzip.open(tmp_ctx.name, 'wt') as temp_file:
            for ad_creative in [ad_creative for ad_creative_req in
                                ad_creative_req_list for ad_creative in
                                ad_creative_req.execute()]:
                json.dump(ad_creative._json, temp_file)
                temp_file.write('\n')

This code was working fine until 14 JUN and suddenly came up from 15 JUN.

MardanovTimur commented 1 year ago

@SoochangChung hi! Did you solve you problem? I have the same problem when im getting creative data via this lib.

stcheng commented 1 year ago

Hello @SoochangChung @MardanovTimur did you try to upgrade to the latest version? We have resolved this issue in our latest version.

MardanovTimur commented 1 year ago

@stcheng, thanks, on the latest version seems ok