CONSUMER_KEY = 'your consumer key'
CONSUMER_SECRET = 'your consumer secret'
ACCESS_TOKEN = 'user access token'
ACCESS_TOKEN_SECRET = 'user access token secret'
ADS_ACCOUNT = 'ads account id'

# initialize the twitter ads api client
client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

# load up the account instance, campaign and line item
account = client.accounts(ADS_ACCOUNT)
campaign = account.campaigns().next()
line_item = account.line_items(None, campaign_ids=campaign.id).next()

# create request for a simple nullcasted tweet
tweet1 = Tweet.create(account, text='There can be only one...')

# promote the tweet using our line item
promoted_tweet = PromotedTweet(account)
promoted_tweet.line_item_id = line_item.id
promoted_tweet.tweet_id = tweet1['id']
promoted_tweet.save()

# create request for a nullcasted tweet with a website card
website_card = WebsiteCard.all(account).next()
text = "Fine. There can be two. {card_url}".format(card_url=website_card.preview_url)
tweet2 = Tweet.create(account, text)

# promote the tweet using our line item
promoted_tweet = PromotedTweet(account)
promoted_tweet.line_item_id = line_item.id
Esempio n. 2
0
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)

# preview an existing tweet
Tweet.preview(account, id=661845592138776576)

# preview a new tweet
Tweet.preview(account, text='Hello @AdsAPI!')
Tweet.preview(account,
              text='Hello @AdsAPI!',
              media_ids=[634458428836962305, 634458428836962306])

# preview a new tweet with an embedded card
website_card = WebsiteCard.all(account).next()
Tweet.preview(account, text='Hello @AdsAPI!', card_id=website_card.id)

# create a new null-casted tweet
Tweet.create(account, text='Hello from Python @AdsAPI!')
Tweet.create(account,
             text='Hello @AdsAPI!',
CONSUMER_KEY = 'your consumer key'
CONSUMER_SECRET = 'your consumer secret'
ACCESS_TOKEN = 'user access token'
ACCESS_TOKEN_SECRET = 'user access token secret'
ADS_ACCOUNT = 'ads account id'

# initialize the twitter ads api client
client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

# load up the account instance, campaign and line item
account = client.accounts(ADS_ACCOUNT)
campaign = account.campaigns().next()
line_item = account.line_items(None, params={'campaign_id': campaign.id}).next()

# create request for a simple nullcasted tweet
tweet1 = Tweet.create(account, 'There can be only one...')

# promote the tweet using our line item
promoted_tweet = PromotedTweet(account)
promoted_tweet.line_item_id = line_item.id
promoted_tweet.tweet_id = tweet1['id']
promoted_tweet.save()

# create request for a nullcasted tweet with a website card
website_card = WebsiteCard.all(account).next()
status = "Fine. There can be two. {card_url}".format(card_url=website_card.preview_url)
tweet2 = Tweet.create(account, status)

# promote the tweet using our line item
promoted_tweet = PromotedTweet(account)
promoted_tweet.line_item_id = line_item.id
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)

# preview an existing tweet
Tweet.preview(account, id=661845592138776576)

# preview a new tweet
Tweet.preview(account, text='Hello @AdsAPI!')
Tweet.preview(account, text='Hello @AdsAPI!', media_ids=[634458428836962305, 634458428836962306])

# preview a new tweet with an embedded card
website_card = WebsiteCard.all(account).next()
Tweet.preview(account, text='Hello @AdsAPI!', card_id=website_card.id)

# create a new null-casted tweet
Tweet.create(account, text='Hello from Python @AdsAPI!')
Tweet.create(account, text='Hello @AdsAPI!', media_ids=[634458428836962305, 634458428836962306])

# create a new null-casted tweet with an embedded card
website_card = WebsiteCard.all(account).next()
Esempio n. 5
0
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)

# 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)
# https://twitter.com/apimctestface/status/1372283476615958529
# initialize the twitter ads api client
client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN,
                ACCESS_TOKEN_SECRET)

# load up the account instance, campaign and line item
account = client.accounts(ACCOUNT_ID)

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

campaign = account.campaigns().next()
line_item = account.line_items(None, campaign_ids=campaign.id).next()

# create request for a simple nullcasted tweet
tweet1 = Tweet.create(account,
                      text='There can be only one...',
                      as_user_id=user_id)

# create request for a nullcasted tweet with a website card
website_card = WebsiteCard.all(account).next()
tweet2 = Tweet.create(account,
                      text='Fine. There can be two.',
                      as_user_id=user_id,
                      card_uri=website_card.card_uri)

# promote the tweet using our line item
tweet_ids = [tweet1['id'], tweet2['id']]

response = PromotedTweet.attach(account,
                                line_item_id=line_item.id,
                                tweet_ids=tweet_ids)
Esempio n. 7
0
CONSUMER_SECRET = 'your consumer secret'
ACCESS_TOKEN = 'user access token'
ACCESS_TOKEN_SECRET = 'user access token secret'
ADS_ACCOUNT = 'ads account id'

# initialize the twitter ads api client
client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN,
                ACCESS_TOKEN_SECRET)

# load up the account instance, campaign and line item
account = client.accounts(ADS_ACCOUNT)
campaign = account.campaigns().next()
line_item = account.line_items(None, campaign_ids=campaign.id).next()

# create request for a simple nullcasted tweet
tweet1 = Tweet.create(account, text='There can be only one...')

# promote the tweet using our line item
promoted_tweet = PromotedTweet(account)
promoted_tweet.line_item_id = line_item.id
promoted_tweet.tweet_id = tweet1['id']
promoted_tweet.save()

# create request for a nullcasted tweet with a website card
website_card = WebsiteCard.all(account).next()
text = "Fine. There can be two. {card_url}".format(
    card_url=website_card.preview_url)
tweet2 = Tweet.create(account, text)

# promote the tweet using our line item
promoted_tweet = PromotedTweet(account)
Esempio n. 8
0
CONSUMER_SECRET = 'your consumer secret'
ACCESS_TOKEN = 'user access token'
ACCESS_TOKEN_SECRET = 'user access token secret'
ADS_ACCOUNT = 'ads account id'

# initialize the twitter ads api client
client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN,
                ACCESS_TOKEN_SECRET)

# load up the account instance, campaign and line item
account = client.accounts(ADS_ACCOUNT)
campaign = account.campaigns().next()
line_item = account.line_items(None, campaign_ids=campaign.id).next()

# create request for a simple nullcasted tweet
tweet1 = Tweet.create(account, 'There can be only one...')

# promote the tweet using our line item
promoted_tweet = PromotedTweet(account)
promoted_tweet.line_item_id = line_item.id
promoted_tweet.tweet_id = tweet1['id']
promoted_tweet.save()

# create request for a nullcasted tweet with a website card
website_card = WebsiteCard.all(account).next()
status = "Fine. There can be two. {card_url}".format(
    card_url=website_card.preview_url)
tweet2 = Tweet.create(account, status)

# promote the tweet using our line item
promoted_tweet = PromotedTweet(account)

CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_TOKEN = ''
ACCESS_TOKEN_SECRET = ''
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)

# most recent Media Library video
ml = MediaLibrary(account).all(account, media_type=MEDIA_TYPE.VIDEO)
media_key = ml.first.media_key

# create Poll Card with video
pc = PollCard(account)
pc.duration_in_minutes = 10080 # one week
pc.first_choice = 'Northern'
pc.second_choice = 'Southern'
pc.name = ml.first.name + ' poll card from SDK'
pc.media_key = media_key
pc.save()

# create Tweet
Tweet.create(account, text='Which hemisphere do you prefer?', card_uri=pc.card_uri)
# https://twitter.com/apimctestface/status/973002610033610753
Esempio n. 10
0
# create a new draft tweet
draft_tweet = DraftTweet(account)
draft_tweet.text = 'draft tweet - new'
draft_tweet = draft_tweet.save()
print(draft_tweet.id_str)
print(draft_tweet.text)

# fetch single draft tweet metadata
tweet_id = draft_tweet.id_str
draft_tweet = draft_tweet.load(account, tweet_id)
print(draft_tweet.id_str)
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.text)

# preview draft tweet of current instance (send notification)
draft_tweet.preview()
# or, specify any draft_tweet_id
# draft_tweet.preview(draft_tweet_id='1142020720651673600')

# create a nullcasted tweet using draft tweet metadata
tweet = Tweet.create(account, text=draft_tweet.text)
print(tweet)

# delete draft tweet
# draft_tweet.delete()