Example #1
0
def pushEmails2Twitter(hashedEmails,twCred):

    from twitter_ads.client import Client
    from twitter_ads.audience import TailoredAudience
    from twitter_ads.enum import TA_LIST_TYPES, TA_OPERATIONS

    CONSUMER_KEY = 'your consumer key'
    CONSUMER_SECRET = 'your consumer secret'
    ACCESS_TOKEN = 'access token'
    ACCESS_TOKEN_SECRET = 'access token secret'
    ACCOUNT_ID = 'account id'

    # initialize the client
    client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

    # load the advertiser account instance
    account = client.accounts(ACCOUNT_ID)

    # create a new tailored audience
    audience = TailoredAudience.create(account, '/path/to/file', 'my list', TA_LIST_TYPES.EMAIL)

    # check the processing status
    audience.status()

    # update the tailored audience
    audience.update('/path/to/file', TA_LIST_TYPES.TWITTER_ID, TA_OPERATIONS.REMOVE)
    audience.update('/path/to/file', TA_LIST_TYPES.PHONE_NUMBER, TA_OPERATIONS.ADD)

    # delete the tailored audience
    audience.delete()

    # add users to the account's global opt-out list
    TailoredAudience.opt_out(account, '/path/to/file', TA_OPERATIONS.HANDLE)
Example #2
0
def test_targeted_audiences():
    responses.add(responses.GET,
                  with_resource('/' + API_VERSION + '/accounts/2iqph'),
                  body=with_fixture('accounts_load'))

    responses.add(responses.GET,
                  with_resource('/' + API_VERSION +
                                '/accounts/2iqph/tailored_audiences/2906h'),
                  body=with_fixture('tailored_audiences_load'))

    responses.add(
        responses.GET,
        with_resource(
            '/' + API_VERSION +
            '/accounts/2iqph/tailored_audiences/abc2/targeted?with_active=True'
        ),
        body=with_fixture('targeted_audiences'))

    client = Client(characters(40), characters(40), characters(40),
                    characters(40))

    account = Account.load(client, '2iqph')

    audience = TailoredAudience.load(account, '2906h')
    targeted_audiences = audience.targeted(with_active=True)

    assert isinstance(targeted_audiences, Cursor)
    assert isinstance(targeted_audiences.first.line_items, list)
    assert targeted_audiences.first.campaign_id == '59hod'
    assert targeted_audiences.first.line_items[0]['id'] == '5gzog'
    assert targeted_audiences.first.line_items[0]['name'] == 'test-line-item'
    assert targeted_audiences.first.line_items[0]['servable'] == True
    assert len(responses.calls) == 3
Example #3
0
CONSUMER_KEY = 'your consumer key'
CONSUMER_SECRET = 'your consumer secret'
ACCESS_TOKEN = 'access token'
ACCESS_TOKEN_SECRET = 'access token secret'
ACCOUNT_ID = 'account id'

# initialize the client
client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN,
                ACCESS_TOKEN_SECRET)

# load the advertiser account instance
account = client.accounts(ACCOUNT_ID)

# create a new tailored audience
audience = TailoredAudience.create(account, 'test TA')

# sample user
# all values musth be sha256 hashed
email_hash = hashlib.sha256("*****@*****.**").hexdigest()

# create payload
user = [{
    "operation_type": "Update",
    "params": {
        "users": [{
            "email": [email_hash]
        }]
    }
}]
Example #4
0
from twitter_ads.audience import TailoredAudience
from twitter_ads.enum import TA_LIST_TYPES, TA_OPERATIONS

CONSUMER_KEY = 'your consumer key'
CONSUMER_SECRET = 'your consumer secret'
ACCESS_TOKEN = 'access token'
ACCESS_TOKEN_SECRET = 'access token secret'
ACCOUNT_ID = 'account id'

# initialize the client
client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

# load the advertiser account instance
account = client.accounts(ACCOUNT_ID)

# create a new tailored audience
audience = TailoredAudience.create(account, '/path/to/file', 'my list', TA_LIST_TYPES.EMAIL)

# check the processing status
audience.status()

# update the tailored audience
audience.update('/path/to/file', TA_LIST_TYPES.TWITTER_ID, TA_OPERATIONS.REMOVE)
audience.update('/path/to/file', TA_LIST_TYPES.PHONE_NUMBER, TA_OPERATIONS.ADD)

# delete the tailored audience
audience.delete()

# add users to the account's global opt-out list
TailoredAudience.opt_out(account, '/path/to/file', TA_OPERATIONS.HANDLE)