facebook-python-business-sdk
facebook-python-business-sdk copied to clipboard
AdsPixel.get_stats() results in FacebookBadObjectError
After receiving the response, there is an attempt to call AbstractObject.create_object with the data parameter set to a keyvalue list, where it expects a dict.
In api.build_objects_from_response, the response is this:
dict: {u'data': [{u'timestamp': u'2016-05-31T10:00:00', u'data': [{u'count': 2, u'value': u'null'}], u'aggregation': u'host'},
{u'timestamp': u'2016-05-31T12:00:00', u'data': [{u'count': 1, u'value': u'null'}], u'aggregation': u'host'},
{u'timestamp': u'2016-05-31T16:00:00', u'data': [{u'count': 1, u'value': u'null'}], u'aggregation': u'host'},
{u'timestamp': u'2016-05-31T20:00:00', u'data': [{u'count': 1, u'value': u'null'}], u'aggregation': u'host'},
...]}
response is passed to objectparser.parse_multiple, which iterates through the items in response['data'] and passes them individually to objectparser.parse_single. So objectparser.parse_single receives:
{u'timestamp': u'2016-05-31T10:00:00', u'data': [{u'count': 2, u'value': u'null'}], u'aggregation': u'host'}
objectparser.parse_single passes the u'data' field as-is to AbstractObject.create_object. This results in a FacebookBadObjectError.
Stack trace:
File "facebookads/adobjects/adspixel.py", line 221, in get_stats
return request if pending else request.execute()
File "facebookads/api.py", line 639, in execute
cursor.load_next_page()
File "facebookads/api.py", line 798, in load_next_page
self._queue = self.build_objects_from_response(response)
File "facebookads/api.py", line 807, in build_objects_from_response
return self._object_parser.parse_multiple(response)
File "facebookads/adobjects/objectparser.py", line 90, in parse_multiple
ret.append(self.parse_single(json_obj))
File "facebookads/adobjects/objectparser.py", line 79, in parse_single
self._target_class)
File "facebookads/adobjects/abstractobject.py", line 166, in create_object
new_object._set_data(data)
File "facebookads/adobjects/abstractobject.py", line 93, in _set_data
raise FacebookBadObjectError("Bad data to set object data")
FacebookBadObjectError: Bad data to set object data
Fixed by last commit