I’m grabbing a tweet from the v2 api. It is a reply that I had written, and I get the referenced tweet, but the referenced tweet does not contain the media. Is it possible to fetch that when getting the tweets referenced tweet?

Yes, it should be inside includes portion of the response, provided you also specified the expansions and fields Using fields and expansions | Docs | Twitter Developer Platform

Thanks Igor, I am not seeing a key for this item, found in includes.tweets:

"entities": {
    "urls": [
        {
            "start": 29,
            "end": 52,
            "url": "https://t.co/mDFby7Ta8L",
            "expanded_url": "https://twitter.com/JacobRuizDesign/status/1521505637284294656/photo/1",
            "display_url": "pic.twitter.com/mDFby7Ta8L",
            "media_key": "3_1521505632230150145"
        }
    ]
},

There is an attachments object in the same referenced tweet object above:

"attachments": {
    "media_keys": [
        "3_1521505632230150145"
    ]
},

However, no media in that response containing the item.

My expansions value in the request is:

author_id,referenced_tweets.id,referenced_tweets.id.author_id,in_reply_to_user_id,attachments.media_keys,entities.mentions.username

and tweet.fields is:

created_at,in_reply_to_user_id,public_metrics,referenced_tweets,entities,conversation_id

I’m not sure I understand - what’s the full request you’re making (url and parameters)? Here’s the full payload with all expansions for this tweet: https://twitter.com/JacobRuizDesign/status/1521505637284294656

twarc2 tweet 1521505637284294656 | jq
{
  "data": [
    {
      "referenced_tweets": [
        {
          "type": "replied_to",
          "id": "1521505629784842240"
        }
      ],
      "entities": {
        "urls": [
          {
            "start": 29,
            "end": 52,
            "url": "https://t.co/mDFby7Ta8L",
            "expanded_url": "https://twitter.com/JacobRuizDesign/status/1521505637284294656/photo/1",
            "display_url": "pic.twitter.com/mDFby7Ta8L",
            "media_key": "3_1521505632230150145"
          }
        ]
      },
      "in_reply_to_user_id": "384694808",
      "conversation_id": "1521505629784842240",
      "lang": "en",
      "possibly_sensitive": false,
      "reply_settings": "everyone",
      "text": "Breaking it down into steps: https://t.co/mDFby7Ta8L",
      "public_metrics": {
        "retweet_count": 0,
        "reply_count": 1,
        "like_count": 1,
        "quote_count": 0
      },
      "author_id": "384694808",
      "id": "1521505637284294656",
      "attachments": {
        "media_keys": [
          "3_1521505632230150145"
        ]
      },
      "created_at": "2022-05-03T15:03:06.000Z",
      "source": "Typefully"
    }
  ],
  "includes": {
    "media": [
      {
        "width": 1318,
        "media_key": "3_1521505632230150145",
        "url": "https://pbs.twimg.com/media/FR15T6zVkAEF-ZB.png",
        "type": "photo",
        "height": 772
      }
    ],
    "users": [
      {
        "description": "Daily experiments with design, code, and personal finance.",
        "id": "384694808",
        "url": "https://t.co/K6EJQ29S9N",
        "name": "Jacob Ruiz",
        "profile_image_url": "https://pbs.twimg.com/profile_images/1206519540823158784/GB1zGHg2_normal.jpg",
        "public_metrics": {
          "followers_count": 767,
          "following_count": 376,
          "tweet_count": 1668,
          "listed_count": 0
        },
        "location": "California",
        "verified": false,
        "username": "JacobRuizDesign",
        "entities": {
          "url": {
            "urls": [
              {
                "start": 0,
                "end": 23,
                "url": "https://t.co/K6EJQ29S9N",
                "expanded_url": "http://jacobruiz.com",
                "display_url": "jacobruiz.com"
              }
            ]
          }
        },
        "created_at": "2011-10-04T04:41:27.000Z",
        "protected": false
      }
    ],
    "tweets": [
      {
        "entities": {
          "urls": [
            {
              "start": 185,
              "end": 208,
              "url": "https://t.co/U2pV8PT88l",
              "expanded_url": "https://twitter.com/JacobRuizDesign/status/1521505629784842240/photo/1",
              "display_url": "pic.twitter.com/U2pV8PT88l",
              "media_key": "16_1521505618451845120"
            }
          ]
        },
        "conversation_id": "1521505629784842240",
        "lang": "en",
        "possibly_sensitive": false,
        "reply_settings": "everyone",
        "text": "Chipping away at this feature. The total now updates when toggling transactions on and off.\n\nThe key is that I need to add a isChecked property to the transactions after fetching them. https://t.co/U2pV8PT88l",
        "public_metrics": {
          "retweet_count": 0,
          "reply_count": 1,
          "like_count": 1,
          "quote_count": 0
        },
        "author_id": "384694808",
        "id": "1521505629784842240",
        "attachments": {
          "media_keys": [
            "16_1521505618451845120"
          ]
        },
        "created_at": "2022-05-03T15:03:05.000Z",
        "source": "Typefully"
      }
    ]
  },
  "__twarc": {
    "url": "https://api.twitter.com/2/tweets?expansions=author_id%2Cin_reply_to_user_id%2Creferenced_tweets.id%2Creferenced_tweets.id.author_id%2Centities.mentions.username%2Cattachments.poll_ids%2Cattachments.media_keys%2Cgeo.place_id&tweet.fields=attachments%2Cauthor_id%2Ccontext_annotations%2Cconversation_id%2Ccreated_at%2Centities%2Cgeo%2Cid%2Cin_reply_to_user_id%2Clang%2Cpublic_metrics%2Ctext%2Cpossibly_sensitive%2Creferenced_tweets%2Creply_settings%2Csource%2Cwithheld&user.fields=created_at%2Cdescription%2Centities%2Cid%2Clocation%2Cname%2Cpinned_tweet_id%2Cprofile_image_url%2Cprotected%2Cpublic_metrics%2Curl%2Cusername%2Cverified%2Cwithheld&media.fields=alt_text%2Cduration_ms%2Cheight%2Cmedia_key%2Cpreview_image_url%2Ctype%2Curl%2Cwidth%2Cpublic_metrics&poll.fields=duration_minutes%2Cend_datetime%2Cid%2Coptions%2Cvoting_status&place.fields=contained_within%2Ccountry%2Ccountry_code%2Cfull_name%2Cgeo%2Cid%2Cname%2Cplace_type&ids=1521505637284294656",
    "version": "2.10.3",
    "retrieved_at": "2022-05-03T22:28:32+00:00"
  }
}

The includes only contain objects relevant to data not other tweets inside includes.tweets - to get the media URL for the referenced tweet, 1521505629784842240 you need to make another call to get it.

1 Like

Thanks Igor.

Makes sense now.

1 Like

@IgorBrigadir did anything around that change recently? I feel like I was getting more related details when querying liked_tweets and tweets endpoints recently, but that may just be my imagination.

1 Like

I don’t think anything changed - but the liked tweets endpoint is flaky sometimes, and returns the latest 100 tweets so it could have been just different results? Or some eventual consistency issues? Only thing that comes to mind.