facebook / facebook-python-business-sdk

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

adset.remote_create() error #489

Closed andongya95 closed 6 years ago

andongya95 commented 6 years ago

I am trying to get acquainted with the facebook ads sdk by following the steps in this link: https://developers.facebook.com/docs/marketing-api/buying-api#ad-creative But I got stuck at this step when creating a AdSet:

import datetime
from facebookads.adobjects.adset import AdSet

today = datetime.date.today()
start_time = str(today + datetime.timedelta(weeks=1))
end_time = str(today + datetime.timedelta(weeks=2))

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My Ad Set',
   AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.daily_budget: 1000,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.bid_amount: 2,
    AdSet.Field.targeting: <TARGETING>,
    AdSet.Field.start_time: start_time,
    AdSet.Field.end_time: end_time,
})

adset.remote_create(params={
    'status': AdSet.Status.paused,
})

I am sure I followed every step in that link, but it generates this error:

AttributeError                            Traceback (most recent call last)
<ipython-input-11-484ba26def8a> in <module>()
     16 })
     17 
---> 18 adset.remote_create()
     19 
     20 print(adset)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\facebookads\adobjects\abstractcrudobject.py in remote_create(self, batch, failure, files, params, success, api_version)
    294             )
    295         else:
--> 296             response = request.execute()
    297             self._set_data(response._json)
    298             self._clear_history()

~\AppData\Local\Continuum\anaconda3\lib\site-packages\facebookads\api.py in execute(self)
    667             params['fields'] = ','.join(self._fields)
    668         with open_files(self._file_params) as files:
--> 669             response = self._api.call(
    670                 method=self._method,
    671                 path=(self._path),

AttributeError: 'NoneType' object has no attribute 'call'
IrinaMityayeva commented 6 years ago

Try to init your api: from facebook_business import FacebookAdsApi FacebookAdsApi.init(config['app_id'], config['app_secret'], config['access_token'])

andongya95 commented 6 years ago

I promise I did. There are several steps in that link before this one and those codes ran successfully. So it is not about the API config but something wrong with the codes.

jingping2015 commented 6 years ago
  1. make sure you download the latest facebook_business
  2. Make sure you read config or set your app_id/access_token correctly.

We've been unable to reproduce this bug, and are unable to investigate further. We are closing the issue for now, if you identify a test case we can use to reproduce your bug feel free to re-open.