Promoted Tweets Endpoint in Python SDK v1


#1

I am using the Python SDK (v1) of the Ads API but I do not see the Promoted Tweet endpoint (accounts/:account_id/promoted_tweets) in the Account class. I have added my own but should I be using another?


#2

Hey @stevea.jones,

The Promoted Tweet endpoint can be found in the twitter_ads.creative package. Please take a look at the example code for more details.

Hope that helps!


#3

Thanks for your response. I had looked at the package and example before, but I was not able to see how to get a list of all promoted tweets for an account, campaign or line item. (Sorry, I am fairly new to Python, so if I am missing something obvious, please let me know.)

I ended up modifying the account.py package and added the following under the Account class:

def promoted_tweets(self, id=None, **kwargs):
    """
    Returns a collection of promoted_tweets available to the current account.
    """
    return self._load_resource(PromotedTweet, id, **kwargs)

And used it similar to this in my code:
for w_promoted_tweet in (x for x in w_account.promoted_tweets()):…

This seems to work, but I am not sure if it always returns everything…?

Thanks
Steve


#4

Hey @stevea.jones,

You are correct in that your method will absolutely work. All those methods are helper methods or shortcuts to GET endpoints. You can achieve the same result as such:

from twitter_ads.creative import PromotedTweet

# grab all promoted tweets from a line_item
promoted_tweet = PromotedTweet(id=line_item_id)

# use the cursor object to 'get' all the tweets we need
promoted_tweet_id = promoted_tweet.all(account).next().id

# print all promoted tweet id's

for tweet in promoted_tweet.all(account):
    print tweet.id

Hope that helps!


#5

Awesome - thanks!