Skip to content

Commit a3dd581

Browse files
tushdanteTom Osowski
and
Tom Osowski
authored
Ads API v11 (#296)
* updated cards class and examples * added tests * remove deprecated card types * line item budget optimization changes * bump version * removed references to video website cards * removed start/end times from campaigns * Remove _str versions of parameters Co-authored-by: Tom Osowski <tosowski@twitter.com>
1 parent 2567d75 commit a3dd581

15 files changed

+1064
-176
lines changed

examples/cards.py

+70-10
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,89 @@
11
from twitter_ads.client import Client
22
from twitter_ads.creative import Card
3-
from twitter_ads.campaign import Tweet
4-
from twitter_ads.restapi import UserIdLookup
3+
from twitter_ads.http import Request
54

65

76
CONSUMER_KEY = 'your consumer key'
87
CONSUMER_SECRET = 'your consumer secret'
9-
ACCESS_TOKEN = 'access token'
10-
ACCESS_TOKEN_SECRET = 'access token secret'
11-
ACCOUNT_ID = 'account id'
8+
ACCESS_TOKEN = 'user access token'
9+
ACCESS_TOKEN_SECRET = 'user access token secret'
10+
ACCOUNT_ID = 'ads account id'
1211

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

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

19-
# create the card
20-
name = 'video website card'
21-
components = [{"type":"MEDIA","media_key":"13_1191948012077092867"},{"type":"DETAILS","title":"Twitter","destination":{"type":"WEBSITE", "url":"http://twitter.com/"}}]
22-
video_website_card = Card.create(account, name=name, components=components)
18+
# fetch all
19+
card = Card.all(account, card_ids="1502039998987587584").first
20+
21+
# fetch by card-id
22+
card = Card.load(account=account, id="1502039998987587584")
23+
24+
# edit card destination.url
25+
card.components= [
26+
{
27+
"media_key": "13_794652834998325248",
28+
"media_metadata": {
29+
"13_794652834998325248": {
30+
"type": "VIDEO",
31+
"url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4",
32+
"width": 640,
33+
"height": 360,
34+
"video_duration": 7967,
35+
"video_aspect_ratio": "16:9"
36+
}
37+
},
38+
"type": "MEDIA"
39+
},
40+
{
41+
"title": "Twitter",
42+
"destination": {
43+
"url": "http://twitter.com/newvalue",
44+
"type": "WEBSITE"
45+
},
46+
"type": "DETAILS"
47+
}
48+
]
49+
50+
card.save()
51+
print(card.components)
52+
53+
# create new card
54+
newcard = Card(account=account)
55+
newcard.name="my new card"
56+
components= [
57+
{
58+
"media_key": "13_794652834998325248",
59+
"media_metadata": {
60+
"13_794652834998325248": {
61+
"type": "VIDEO",
62+
"url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4",
63+
"width": 640,
64+
"height": 360,
65+
"video_duration": 7967,
66+
"video_aspect_ratio": "16:9"
67+
}
68+
},
69+
"type": "MEDIA"
70+
},
71+
{
72+
"title": "Twitter",
73+
"destination": {
74+
"url": "http://twitter.com/login",
75+
"type": "WEBSITE"
76+
},
77+
"type": "DETAILS"
78+
}
79+
]
80+
newcard.components=components
81+
newcard.save()
82+
print(newcard.id)
2383

2484
# get user_id for as_user_id parameter
2585
user_id = UserIdLookup.load(account, screen_name='your_twitter_handle_name').id
2686

2787
# create a tweet using this new card
28-
Tweet.create(account, text='Created from the SDK', as_user_id=user_id, card_uri=video_website_card.card_uri)
88+
Tweet.create(account, text='Created from the SDK', as_user_id=user_id, card_uri=card.card_uri)
2989
# https://twitter.com/apimctestface/status/1372283476615958529

examples/draft_tweet.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@
2222
# fetch draft tweets from a given account
2323
tweets = DraftTweet.all(account)
2424
for tweet in tweets:
25-
print(tweet.id_str)
25+
print(tweet.id)
2626
print(tweet.text)
2727

2828
# create a new draft tweet
2929
draft_tweet = DraftTweet(account)
3030
draft_tweet.text = 'draft tweet - new'
3131
draft_tweet.as_user_id = user_id
3232
draft_tweet = draft_tweet.save()
33-
print(draft_tweet.id_str)
33+
print(draft_tweet.id)
3434
print(draft_tweet.text)
3535

3636
# fetch single draft tweet metadata
37-
tweet_id = draft_tweet.id_str
37+
tweet_id = draft_tweet.id
3838
draft_tweet = draft_tweet.load(account, tweet_id)
39-
print(draft_tweet.id_str)
39+
print(draft_tweet.id)
4040
print(draft_tweet.text)
4141

4242
# update (PUT) metadata
4343
draft_tweet.text = 'draft tweet - update'
4444
draft_tweet = draft_tweet.save()
45-
print(draft_tweet.id_str)
45+
print(draft_tweet.id)
4646
print(draft_tweet.text)
4747

4848
# create a nullcasted tweet using draft tweet metadata

tests/fixtures/analytics_async_get.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"start_time": "2019-01-01T00:00:00Z",
1313
"segmentation_type": null,
1414
"url": "https://ton.twimg.com/advertiser-api-async-analytics/stats.json.gz",
15-
"id_str": "111111111111111111",
15+
"id": "111111111111111111",
1616
"entity_ids": [
1717
"aaaa"
1818
],

tests/fixtures/analytics_async_post.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"start_time": "2019-01-01T00:00:00Z",
1919
"segmentation_type": null,
2020
"url": null,
21-
"id_str": "111111111111111111",
21+
"id": "111111111111111111",
2222
"entity_ids": [
2323
"aaaa"
2424
],

0 commit comments

Comments
 (0)