-
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.
* 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 <[email protected]>
- Loading branch information
Showing
15 changed files
with
1,064 additions
and
176 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 |
---|---|---|
@@ -1,29 +1,89 @@ | ||
from twitter_ads.client import Client | ||
from twitter_ads.creative import Card | ||
from twitter_ads.campaign import Tweet | ||
from twitter_ads.restapi import UserIdLookup | ||
from twitter_ads.http import Request | ||
|
||
|
||
CONSUMER_KEY = 'your consumer key' | ||
CONSUMER_SECRET = 'your consumer secret' | ||
ACCESS_TOKEN = 'access token' | ||
ACCESS_TOKEN_SECRET = 'access token secret' | ||
ACCOUNT_ID = 'account id' | ||
ACCESS_TOKEN = 'user access token' | ||
ACCESS_TOKEN_SECRET = 'user access token secret' | ||
ACCOUNT_ID = 'ads 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 the card | ||
name = 'video website card' | ||
components = [{"type":"MEDIA","media_key":"13_1191948012077092867"},{"type":"DETAILS","title":"Twitter","destination":{"type":"WEBSITE", "url":"http://twitter.com/"}}] | ||
video_website_card = Card.create(account, name=name, components=components) | ||
# fetch all | ||
card = Card.all(account, card_ids="1502039998987587584").first | ||
|
||
# fetch by card-id | ||
card = Card.load(account=account, id="1502039998987587584") | ||
|
||
# edit card destination.url | ||
card.components= [ | ||
{ | ||
"media_key": "13_794652834998325248", | ||
"media_metadata": { | ||
"13_794652834998325248": { | ||
"type": "VIDEO", | ||
"url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", | ||
"width": 640, | ||
"height": 360, | ||
"video_duration": 7967, | ||
"video_aspect_ratio": "16:9" | ||
} | ||
}, | ||
"type": "MEDIA" | ||
}, | ||
{ | ||
"title": "Twitter", | ||
"destination": { | ||
"url": "http://twitter.com/newvalue", | ||
"type": "WEBSITE" | ||
}, | ||
"type": "DETAILS" | ||
} | ||
] | ||
|
||
card.save() | ||
print(card.components) | ||
|
||
# create new card | ||
newcard = Card(account=account) | ||
newcard.name="my new card" | ||
components= [ | ||
{ | ||
"media_key": "13_794652834998325248", | ||
"media_metadata": { | ||
"13_794652834998325248": { | ||
"type": "VIDEO", | ||
"url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", | ||
"width": 640, | ||
"height": 360, | ||
"video_duration": 7967, | ||
"video_aspect_ratio": "16:9" | ||
} | ||
}, | ||
"type": "MEDIA" | ||
}, | ||
{ | ||
"title": "Twitter", | ||
"destination": { | ||
"url": "http://twitter.com/login", | ||
"type": "WEBSITE" | ||
}, | ||
"type": "DETAILS" | ||
} | ||
] | ||
newcard.components=components | ||
newcard.save() | ||
print(newcard.id) | ||
|
||
# get user_id for as_user_id parameter | ||
user_id = UserIdLookup.load(account, screen_name='your_twitter_handle_name').id | ||
|
||
# create a tweet using this new card | ||
Tweet.create(account, text='Created from the SDK', as_user_id=user_id, card_uri=video_website_card.card_uri) | ||
Tweet.create(account, text='Created from the SDK', as_user_id=user_id, card_uri=card.card_uri) | ||
# https://twitter.com/apimctestface/status/1372283476615958529 |
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
Oops, something went wrong.