-
Notifications
You must be signed in to change notification settings - Fork 114
Ads API v11 #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tushdante
merged 35 commits into
xdevplatform:master
from
tushdante:tbhushan/ads-api-v11
May 27, 2022
Merged
Ads API v11 #296
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
0afe951
Create pythonpublish.yml
tushdante ba9e7ce
Merge pull request #1 from tushdante/tushar-ci-cd
tushdante 6382675
Update pythonpublish.yml
tushdante ef98d73
Update __init__.py
tushdante 7de97b5
Update __init__.py
tushdante 0a04af6
Merge pull request #2 from twitterdev/master
tushdante a78076d
Create python-package.yml
tushdante 4e0cabd
Update python-package.yml
tushdante 4206d23
Update python-package.yml
tushdante 3739def
Update python-package.yml
tushdante 8f25cec
removed windows
tushdante e6dda1d
removed python 3.8
tushdante 80e1edb
Update python-package.yml
tushdante 7488d84
remove pypy
tushdante 2d3483b
Merge pull request #3 from tushdante/tushdante-test-ci
tushdante 30f6eaa
Update python-package.yml
tushdante b8613db
Create pythonpublish.yml
tushdante 906083b
Merge branch 'master' of github.com:tushdante/twitter-python-ads-sdk
tushdante 863ef32
# This is a combination of 2 commits.
tushdante f946d60
Merge branch 'master' of github.com:tushdante/twitter-python-ads-sdk
tushdante beffafa
Merge https://github.com/twitterdev/twitter-python-ads-sdk
tushdante 93d05a2
Merge branch 'master' of https://github.com/twitterdev/twitter-python…
tushdante c726177
Merge branch 'twitterdev-master'
tushdante 421589e
updated cards class and examples
tushdante 559bafe
added tests
tushdante d3cf0ae
fix flake8 tests
tushdante 2c358cc
updated cards example
tushdante bfab444
remove deprecated card types
tushdante b26d361
line item budget optimization changes
tushdante f1316a4
bump version
tushdante 223975e
removed references to video website cards
tushdante c6ee7f1
removed start/end times from campaigns
tushdante 0521e81
Remove string versions of IDs
fe1a3c0
Remove string versions of IDs
22801f8
Remove _str versions of parameters
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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