def test_promoted_tweets_attach(): responses.add(responses.GET, with_resource('/' + API_VERSION + '/accounts/2iqph'), body=with_fixture('accounts_load'), content_type='application/json') responses.add(responses.POST, with_resource('/' + API_VERSION + '/accounts/2iqph/promoted_tweets'), body=with_fixture('promoted_tweets_attach'), content_type='application/json') client = Client( characters(40), characters(40), characters(40), characters(40) ) account = Account.load(client, '2iqph') response = PromotedTweet.attach( account, line_item_id='2b7xw', tweet_ids=['585127452231467008'] ) assert isinstance(response, Cursor) assert response.count == 1 assert response.first.id == '6thl4'
def test_promoted_tweets_all(): responses.add(responses.GET, with_resource('/' + API_VERSION + '/accounts/2iqph'), body=with_fixture('accounts_load'), content_type='application/json') responses.add(responses.GET, with_resource('/' + API_VERSION + '/accounts/2iqph/promoted_tweets'), body=with_fixture('promoted_tweets_all'), content_type='application/json') client = Client( characters(40), characters(40), characters(40), characters(40) ) account = Account.load(client, '2iqph') cursor = PromotedTweet.all(account) assert cursor is not None assert isinstance(cursor, Cursor) assert cursor.count == 20 promoted_tweet = cursor.next() assert promoted_tweet.id == '6thl4' assert promoted_tweet.entity_status == 'ACTIVE'
def test_promoted_tweets_load(): responses.add(responses.GET, with_resource('/' + API_VERSION + '/accounts/2iqph'), body=with_fixture('accounts_load'), content_type='application/json') responses.add(responses.GET, with_resource('/' + API_VERSION + '/accounts/2iqph/promoted_tweets/6thl4'), body=with_fixture('promoted_tweets_load'), content_type='application/json') client = Client(characters(40), characters(40), characters(40), characters(40)) account = Account.load(client, '2iqph') promoted_tweet = PromotedTweet.load(account, '6thl4') assert promoted_tweet.id == '6thl4' assert promoted_tweet.entity_status == 'ACTIVE'
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 promoted_tweet.tweet_id = tweet2['id'] promoted_tweet.save()
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) for i in response: print(i.id) print(i.tweet_id)
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 promoted_tweet.tweet_id = tweet2['id'] promoted_tweet.save()