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

CustomAudience ModuleNotFoundError: No module named 'facebookads' #500

Closed jinshang closed 6 years ago

jinshang commented 6 years ago

Hi Guys,

I am a noob to Python and would like to write a python script for creating lookalike. I wrote the script as per what you recommended.

from facebookads import FacebookAdsApi from facebookads.adobjects.customaudience import CustomAudience

lookalike = CustomAudience(parent_id='act_1053708968139158') lookalike.update({ CustomAudience.Field.name: 'My lookalike audience', CustomAudience.Field.subtype: CustomAudience.Subtype.lookalike, CustomAudience.Field.origin_audience_id: '23842892015900245', CustomAudience.Field.lookalike_spec: { 'ratio': 0.2, 'type': 'similarity', 'country': 'TH', }, })

lookalike.remote_create() print(lookalike)

However, I received an error message

Traceback (most recent call last): File "lal.py", line 21, in from facebookads import FacebookAdsApi ModuleNotFoundError: No module named 'facebookads'

Do you know what is going wrong here?

Thank you and cheers,

jinshang

jinshang commented 6 years ago

When I changed FacebookAds to Facebook_Business then I received the following error messages

WARNING:root:parent_id as a parameter of constructor is being deprecated. /Users/davids/Downloads/fb/facebook_business/utils/api_utils.py:30: UserWarning: value of lookalike_spec might not be compatible. Expect string; got <class 'dict'> warnings.warn(message) Traceback (most recent call last): File "lal.py", line 36, in lookalike.remote_create() File "/Users/davids/Downloads/fb/facebook_business/adobjects/abstractcrudobject.py", line 296, in remote_create response = request.execute() File "/Users/davids/Downloads/fb/facebook_business/api.py", line 662, in execute response = self._api.call( AttributeError: 'NoneType' object has no attribute 'call'

shootingsyh commented 6 years ago

Can you try to warp the lookalike_spec as a json string?

jinshang commented 6 years ago

HI Shootingsyh,

I am a beginner to json, do you mind to give me a sample?

Thank you and cheers,

Jinshang

jingping2015 commented 6 years ago

You need to do

from facebook_business.api import FacebookAdsApi
jinshang commented 6 years ago

from facebook_business.api import FacebookAdsApi from facebook_business.adobjects.customaudience import CustomAudience

lookalike = CustomAudience(parent_id='act_1053708968139158') lookalike.update({ CustomAudience.Field.name: 'My lookalike audience', CustomAudience.Field.subtype: CustomAudience.Subtype.lookalike, CustomAudience.Field.origin_audience_id: '23842892015900245', CustomAudience.Field.lookalike_spec: { 'ratio': 0.2, 'type': 'similarity', 'country': 'TH', }, })

lookalike.remote_create() print(lookalike)

This is what I did