2

I'm trying to create Ad-set using the code given in developer's site. Here is link

Code:

from facebookads.adobjects.adset import AdSet
from facebookads.adobjects.targeting import Targeting

adset = AdSet(parent_id='act_Account-ID')
adset.update({
    AdSet.Field.name: 'My Ad Set',
    AdSet.Field.campaign_id: 'Campaingn-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.Field.geo_locations: {
            'countries': ['US'],
        },
    },
})

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

Error:

WARNING:root:parent_id as a parameter of constructor is being deprecated.
Traceback (most recent call last):
  File "adset_test.py", line 88, in <module>
    'status': AdSet.Status.paused,
  File "D:\PERSONAL DATA\python\Online Compitions\Job Test\AbsentiaVR\env\lib\site-packages\facebookads\adobjects\abstractcrudobject.py", line 296, in remote_create
    response = request.execute()
  File "D:\PERSONAL DATA\python\Online Compitions\Job Test\AbsentiaVR\env\lib\site-packages\facebookads\api.py", line 669, in execute
    response = self._api.call(
AttributeError: 'NoneType' object has no attribute 'call'

Note:

I have used right values in act_Account-ID and 'Campaingn-ID'.

Please help to solve this issue. Thanks in advance.

shaik moeed
  • 5,300
  • 1
  • 18
  • 54
  • 1
    From what I understand, `` and `` params in `parent_id` and `campaign_id` fields in the example are to be substituted with valid values accepted by the API. I see that you've used them as it is. Try using appropriate values in those fields, that might solve the issue. – Vignesh Bayari R. Feb 01 '19 at 07:36
  • I agree with @VigneshBayariR. You have to replace those with actual values. How to create ad account id: https://developers.facebook.com/docs/marketing-api/reference/ad-account/#Creating – singleton Feb 01 '19 at 07:53
  • @VigneshBayariR. Thanks for your response. I have used actual values in it. Just for security purpose, I removed in question. – shaik moeed Feb 01 '19 at 08:50
  • From what I can think of, it has to be something to do with the instantiation. – Vignesh Bayari R. Feb 01 '19 at 09:31
  • @VigneshBayariR., Can you please elaborate? – shaik moeed Feb 01 '19 at 09:38
  • [This](https://stackoverflow.com/questions/40361101/facebook-python-marketing-api-attributeerror) might help. – Vignesh Bayari R. Feb 01 '19 at 09:45
  • @VigneshBayariR., you solution solve the issue. But, I'm facing issue with version. How to upgrade to `v3.2`? . Can you please help me with that? – shaik moeed Feb 01 '19 at 10:13
  • You'll have to install facebook_business and make use of that. More details [here](https://developers.facebook.com/ads/blog/post/2018/10/23/marketing-api-v32/). – Vignesh Bayari R. Feb 01 '19 at 10:21

1 Answers1

3

Apparently, that python client for their API has been deprecated and this is to be used now.

Initialising the API before instantiating the AdSet object should not result in that issue:

from facebook_business.api import FacebookAdsApi

my_app_id = 'your-app-id'
my_app_secret = 'your-appsecret'
my_access_token = 'your-page-access-token'
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
  • 1
    Thanks. I have also tried the same. I'm using facebook_business to create campaign, adsets and ads. Here, the instantiating step is more important, which is not mentioned in Doc. – shaik moeed Feb 01 '19 at 10:28