Getting tweet_id from promoted tweets

python
promoted-tweets

#1

I am trying to get the text for promoted tweets. From what i understand, For this i need to find the tweet_id of the promoted tweet and then make the REST API call.

However, my call for promoted tweets by Id does not work correctly and instead throws the list of all promoted tweets for the account.

resource = '/4/accounts/{account_id}/promoted_tweets'.format(account_id=account.id)
    params = {'account_id':'1887vp',
            'promoted_tweet_id': '23xk6v'}, #this is where promoted tweet ids will go
    response = Request(client, 'get', resource, params=params).perform()
    print (response.body['data'])

so instead of getting the reply only for this promoted tweet id, i get it for the whole account. What is the miss here?
@juanshishido @Outflink @imit8me


#2

You can either do one of two things:

  1. Make promoted_tweet_id a URL parameter, which corresponds to GET accounts/:account_id/promoted_tweets/:promoted_tweet_id
  2. Change the parameter to promoted_tweet_ids, which corresponds to GET accounts/:account_id/promoted_tweets

If you’re using the Python SDK, you can do the following:

>>> ptw = PromotedTweet.load(account=account, id="270k4z")
>>> type(ptw)
twitter_ads.creative.PromotedTweet
>>> ptw.tweet_id
'1039960130727464960'

If you’re using requests directly, you can do:

>>> url = "https://ads-api.twitter.com/4/accounts/{account_id}/promoted_tweets/{promoted_tweet_id}".format(account_id=ACCOUNT_ID, promoted_tweet_id="270k4z")
>>> r = requests.get(url, auth=auth)
>>> r.json()["data"]["tweet_id"]
'1039960130727464960'

Please also see the example here.