-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Removed scoped timeline endpoint * added granular tap placements * added advertiser business categories endpoint * updated serving_status to entity_status for media creatives * replaced reach estimate with audience summary * added audience summary and tests
- Loading branch information
Showing
9 changed files
with
154 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from twitter_ads.client import Client | ||
from twitter_ads.targeting import AudienceSummary | ||
|
||
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) | ||
|
||
# targeting criteria params | ||
params = { | ||
"targeting_criteria": [ | ||
{ | ||
"targeting_type":"LOCATION", | ||
"targeting_value":"96683cc9126741d1" | ||
}, | ||
{ | ||
"targeting_type":"BROAD_KEYWORD", | ||
"targeting_value":"cats" | ||
}, | ||
{ | ||
"targeting_type":"SIMILAR_TO_FOLLOWERS_OF_USER", | ||
"targeting_value": "14230524" | ||
}, | ||
{ | ||
"targeting_type":"SIMILAR_TO_FOLLOWERS_OF_USER", | ||
"targeting_value": "90420314" | ||
} | ||
] | ||
} | ||
|
||
audience_summary = AudienceSummary.load(account=account, params=params) | ||
|
||
print (audience_summary.audience_size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"request": { | ||
"params": { | ||
"targeting_criteria": null, | ||
"account_id": "2iqph" | ||
} | ||
}, | ||
"data": { | ||
"audience_size": { | ||
"min": 41133600, | ||
"max": 50274400 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import responses | ||
import unittest | ||
|
||
from tests.support import with_resource, with_fixture, characters | ||
|
||
from twitter_ads.account import Account | ||
from twitter_ads.client import Client | ||
from twitter_ads.targeting import AudienceSummary | ||
from twitter_ads import API_VERSION | ||
|
||
|
||
@responses.activate | ||
def test_audience_summary(): | ||
responses.add(responses.GET, | ||
with_resource('/' + API_VERSION + '/accounts/2iqph'), | ||
body=with_fixture('accounts_load'), | ||
content_type='application/json') | ||
|
||
responses.add(responses.POST, | ||
with_resource('/' + API_VERSION + '/accounts/2iqph/audience_summary'), | ||
body=with_fixture('audience_summary'), | ||
content_type='application/json') | ||
|
||
client = Client( | ||
characters(40), | ||
characters(40), | ||
characters(40), | ||
characters(40) | ||
) | ||
|
||
account = Account.load(client, '2iqph') | ||
|
||
params = { | ||
"targeting_criteria": [ | ||
{ | ||
"targeting_type":"LOCATION", | ||
"targeting_value":"96683cc9126741d1" | ||
}, | ||
{ | ||
"targeting_type":"BROAD_KEYWORD", | ||
"targeting_value":"cats" | ||
}, | ||
{ | ||
"targeting_type":"SIMILAR_TO_FOLLOWERS_OF_USER", | ||
"targeting_value": "14230524" | ||
}, | ||
{ | ||
"targeting_type":"SIMILAR_TO_FOLLOWERS_OF_USER", | ||
"targeting_value": "90420314" | ||
} | ||
] | ||
} | ||
|
||
audience_summary = AudienceSummary.load( | ||
account=account, | ||
params=params | ||
) | ||
|
||
print (audience_summary) | ||
assert audience_summary is not None | ||
assert audience_summary.audience_size is not None | ||
assert audience_summary.audience_size['min'] == 41133600 | ||
assert audience_summary.audience_size['max'] == 50274400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters