Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0afe951
Create pythonpublish.yml
tushdante Feb 10, 2020
ba9e7ce
Merge pull request #1 from tushdante/tushar-ci-cd
tushdante Feb 10, 2020
6382675
Update pythonpublish.yml
tushdante Feb 10, 2020
ef98d73
Update __init__.py
tushdante Feb 10, 2020
7de97b5
Update __init__.py
tushdante Feb 10, 2020
0a04af6
Merge pull request #2 from twitterdev/master
tushdante Oct 5, 2020
a78076d
Create python-package.yml
tushdante Oct 5, 2020
4e0cabd
Update python-package.yml
tushdante Oct 5, 2020
4206d23
Update python-package.yml
tushdante Oct 5, 2020
3739def
Update python-package.yml
tushdante Oct 5, 2020
8f25cec
removed windows
tushdante Oct 5, 2020
e6dda1d
removed python 3.8
tushdante Oct 5, 2020
80e1edb
Update python-package.yml
tushdante Oct 5, 2020
7488d84
remove pypy
tushdante Oct 5, 2020
2d3483b
Merge pull request #3 from tushdante/tushdante-test-ci
tushdante Oct 5, 2020
30f6eaa
Update python-package.yml
tushdante Oct 5, 2020
b8613db
Create pythonpublish.yml
tushdante Feb 10, 2020
906083b
Merge branch 'master' of github.com:tushdante/twitter-python-ads-sdk
tushdante Oct 5, 2020
863ef32
# This is a combination of 2 commits.
tushdante Feb 10, 2020
f946d60
Merge branch 'master' of github.com:tushdante/twitter-python-ads-sdk
tushdante Sep 1, 2021
beffafa
Merge https://github.com/twitterdev/twitter-python-ads-sdk
tushdante Sep 1, 2021
93d05a2
Merge branch 'master' of https://github.com/twitterdev/twitter-python…
tushdante Mar 8, 2022
c726177
Merge branch 'twitterdev-master'
tushdante Mar 8, 2022
421589e
updated cards class and examples
tushdante Mar 15, 2022
559bafe
added tests
tushdante Mar 15, 2022
d3cf0ae
fix flake8 tests
tushdante Mar 15, 2022
2c358cc
updated cards example
tushdante Mar 30, 2022
bfab444
remove deprecated card types
tushdante Mar 31, 2022
b26d361
line item budget optimization changes
tushdante Mar 31, 2022
f1316a4
bump version
tushdante Mar 31, 2022
223975e
removed references to video website cards
tushdante Mar 31, 2022
c6ee7f1
removed start/end times from campaigns
tushdante Apr 12, 2022
0521e81
Remove string versions of IDs
Apr 22, 2022
fe1a3c0
Remove string versions of IDs
Apr 22, 2022
22801f8
Remove _str versions of parameters
Apr 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 70 additions & 10 deletions examples/cards.py
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a separate example for Card Creation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep its been added below

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
10 changes: 5 additions & 5 deletions examples/draft_tweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@
# fetch draft tweets from a given account
tweets = DraftTweet.all(account)
for tweet in tweets:
print(tweet.id_str)
print(tweet.id)
print(tweet.text)

# create a new draft tweet
draft_tweet = DraftTweet(account)
draft_tweet.text = 'draft tweet - new'
draft_tweet.as_user_id = user_id
draft_tweet = draft_tweet.save()
print(draft_tweet.id_str)
print(draft_tweet.id)
print(draft_tweet.text)

# fetch single draft tweet metadata
tweet_id = draft_tweet.id_str
tweet_id = draft_tweet.id
draft_tweet = draft_tweet.load(account, tweet_id)
print(draft_tweet.id_str)
print(draft_tweet.id)
print(draft_tweet.text)

# update (PUT) metadata
draft_tweet.text = 'draft tweet - update'
draft_tweet = draft_tweet.save()
print(draft_tweet.id_str)
print(draft_tweet.id)
print(draft_tweet.text)

# create a nullcasted tweet using draft tweet metadata
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/analytics_async_get.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"start_time": "2019-01-01T00:00:00Z",
"segmentation_type": null,
"url": "https://ton.twimg.com/advertiser-api-async-analytics/stats.json.gz",
"id_str": "111111111111111111",
"id": "111111111111111111",
"entity_ids": [
"aaaa"
],
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/analytics_async_post.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"start_time": "2019-01-01T00:00:00Z",
"segmentation_type": null,
"url": null,
"id_str": "111111111111111111",
"id": "111111111111111111",
"entity_ids": [
"aaaa"
],
Expand Down
Loading