How can I get the image banner of tweet?


#1

At present I use Asynchronous Analytics to get report.

  • First step: create job_id by POST stats/jobs/accounts/:account_id
  • Second step: Get report url by GET stats/jobs/accounts/:account_id using above job_id and download report by response url.

But, How can I get the image in ads manager screen by using Twitter Ads API?


Creative / Content details via API
#2

You’ll have to extract a thumbnail of the media associated with the Tweet.

The view you have selected is the Promoted Tweets view for a given campaign / line item. In the response, you’ll see a tweet_id response attribute. With that ID, you can look up the specific Tweet using the GET statuses/show/:id or GET statuses/lookup endpoints.


#3

Thank you for your answer. But if I use this solution, I am afraid of that it will be out of rate limit because I have many thread to get report in the same time and each thread maybe has many tweet_id to get image.


#4

Your best bet is not to make those requests every time your users access a view where you’d need this images. Rather, you can pull this when the POST accounts/:account_id/promoted_tweets (or related) request is made and store this information on your end.

Hope this helps.


#5

@juanshishido Thank you very much for you explaination. If I use GET statuses/lookup to get image and text of tweet.

I want to ask you one more question. What is the field that stands for value of image banner of tweet? because I see a lot of field in user object. And I am not sure that the image banner field is belong to user object because I see the id of tweet is different with the id in user object.

“user”: {
“profile_background_image_url”: “http://abs.twimg.com/images/themes/theme7/bg.gif”,
“profile_background_image_url_https”: “https://abs.twimg.com/images/themes/theme7/bg.gif”,
“profile_image_url”: “http://pbs.twimg.com/profile_images/448483168580947968/pL4ejHy4_normal.jpeg”,
“profile_image_url_https”: “https://pbs.twimg.com/profile_images/448483168580947968/pL4ejHy4_normal.jpeg”,
“profile_banner_url”: “https://pbs.twimg.com/profile_banners/12/1347981542”,
}


#6

@dudoan1234: The user object includes user information so it would not be a good place to look for the Tweet image.

Let’s take a look at an example. See the following Tweet:

Now, try to find the image URL.

$ twurl -H api.twitter.com "/1.1/statuses/show/919046353770094593.json?trim_user=true"
{
  "created_at": "Sat Oct 14 03:45:00 +0000 2017",
  "id": 919046353770094593,
  "id_str": "919046353770094593",
  "text": "coffee split media key https://t.co/atC63Vn7ZW",
  "truncated": false,
  "entities": {
    "hashtags": [],
    "symbols": [],
    "user_mentions": [],
    "urls": [],
    "media": [
      {
        "id": 908573900237180928,
        "id_str": "908573900237180928",
        "indices": [
          23,
          46
        ],
        "media_url": "http://pbs.twimg.com/media/DJvnJf_UEAAXnzC.jpg",
        "media_url_https": "https://pbs.twimg.com/media/DJvnJf_UEAAXnzC.jpg",
        "url": "https://t.co/atC63Vn7ZW",
        "display_url": "pic.twitter.com/atC63Vn7ZW",
        "expanded_url": "https://twitter.com/apimctestface/status/919046353770094593/photo/1",
        "type": "photo",
        "sizes": {
          "thumb": {
            "w": 150,
            "h": 150,
            "resize": "crop"
          },
          "small": {
            "w": 680,
            "h": 356,
            "resize": "fit"
          },
          "medium": {
            "w": 1200,
            "h": 628,
            "resize": "fit"
          },
          "large": {
            "w": 2048,
            "h": 1072,
            "resize": "fit"
          }
        }
      }
    ]
  },
  "extended_entities": {
    "media": [
      {
        "id": 908573900237180928,
        "id_str": "908573900237180928",
        "indices": [
          23,
          46
        ],
        "media_url": "http://pbs.twimg.com/media/DJvnJf_UEAAXnzC.jpg",
        "media_url_https": "https://pbs.twimg.com/media/DJvnJf_UEAAXnzC.jpg",
        "url": "https://t.co/atC63Vn7ZW",
        "display_url": "pic.twitter.com/atC63Vn7ZW",
        "expanded_url": "https://twitter.com/apimctestface/status/919046353770094593/photo/1",
        "type": "photo",
        "sizes": {
          "thumb": {
            "w": 150,
            "h": 150,
            "resize": "crop"
          },
          "small": {
            "w": 680,
            "h": 356,
            "resize": "fit"
          },
          "medium": {
            "w": 1200,
            "h": 628,
            "resize": "fit"
          },
          "large": {
            "w": 2048,
            "h": 1072,
            "resize": "fit"
          }
        }
      }
    ]
  },
  "source": "<a href=\"https://ads-api.twitter.com\" rel=\"nofollow\">Ads API Internal Test App</a>",
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "in_reply_to_user_id": null,
  "in_reply_to_user_id_str": null,
  "in_reply_to_screen_name": null,
  "user": {
    "id": 756201191646691328,
    "id_str": "756201191646691328"
  },
  "geo": null,
  "coordinates": null,
  "place": null,
  "contributors": null,
  "is_quote_status": false,
  "retweet_count": 0,
  "favorite_count": 0,
  "favorited": false,
  "retweeted": false,
  "possibly_sensitive": false,
  "possibly_sensitive_appealable": false,
  "scopes": {
    "followers": false
  },
  "lang": "en"
}

Hope this helps. Thanks!