0

By following https://developers.facebook.com/docs/marketing-api/audiences-api, I was able to add few users (MOBILE_ADVERTISER_ID) to a Custom Audience using cURL. However, since my goal is to do bulk loading (tens of thousands), I switched to use python SDK.

I'm getting the following error, this is the SCHEMA I've called in cUrl.

    audience.add_users(CustomAudience.Schema.MOBILE_ADVERTISER_ID, users)
AttributeError: type object 'Schema' has no attribute 'MOBILE_ADVERTISER_ID'

Here is my code

from facebookads.adobjects.customaudience import CustomAudience

audience = CustomAudience('custom_audience_id')
users = ['ID_1','ID_2','ID_3']

audience.add_users(CustomAudience.Schema.MOBILE_ADVERTISER_ID, users)

Also, in cUrl I had to pass in ACCESS_TOKEN, but in Python sample code, it's not mentioned at all, how come?

CLO
  • 103
  • 8

1 Answers1

1

I think it should be in small letters: mobile_advertiser_id instead of MOBILE_ADVERTISER_ID.

For the authentication:

from facebookads.api import FacebookAdsApi
from facebookads import objects

my_app_id = '<APP_ID>'
my_app_secret = '<APP_SECRET>'
my_access_token = '<ACCESS_TOKEN>'
proxies = {'http': '<HTTP_PROXY>', 'https': '<HTTPS_PROXY>'} # add proxies if needed
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token, proxies)

ref: https://github.com/facebook/facebook-python-ads-sdk

O.Suleiman
  • 898
  • 1
  • 6
  • 11
  • Thanks, now I need to look for APP_SECRET. What is the proxies? – CLO Jan 14 '18 at 15:22
  • If you have a proxy on your network, you will have to add it. Otherwise, omit it. – O.Suleiman Jan 14 '18 at 15:23
  • I will accept it now, having trouble getting to the app secert. – CLO Jan 14 '18 at 22:41
  • Just go to https://developers.facebook.com/apps/ and click on your app, you will find the app secret directly by clicking show and putting in your Facebook account password. – O.Suleiman Jan 14 '18 at 22:45