What endpoint are you using? dm_events
What API version are you on? v2
Are you using a library or SDK? Which one ? Tweepy library

What is the issue?

I specify that the following issue is not present on Twitter API v1 (I checked).

I want to retrieve the tweets from direct messages sent by participants.
When a participant sends a tweet link, it can be printed in two ways :

  1. The link is displayed once as below :
    image

API result :

{
    "dm_conversation_id": "123456789-987654321",
    "created_at": "2022-12-11T00:05:23.000Z",
    "referenced_tweets": [
        {
            "id": "160003..."
        }
    ],
    "sender_id": "123456789",
    "text": "(...) https://t.co/dl... (...)",
    "id": "160172982...",
    "event_type": "MessageCreate"
}

Here, the tweet is found from the message.

  1. Sometimes the link is displayed twice as below :
    image

API result :

{
    "created_at": "2022-12-11T00:12:18.000Z",
    "id": "123456789",
    "text": "(...) https://t.co/Cq... https://t.co/7z... (...)",
    "sender_id": "133712...",
    "event_type": "MessageCreate",
    "dm_conversation_id": "123456789-987654321"
}

Here, no tweet is found whereas a tweet URL is present.

Below my code :

for response in tweepy.Paginator(
    client.get_direct_message_events,
    max_results=100,
    limit=3,
    expansions=[
        "sender_id", "referenced_tweets.id", "participant_ids"
    ],
    user_fields=[
        "id", "username", "name"
    ],
    dm_event_fields=[
        "id", "created_at", "dm_conversation_id",
        "participant_ids", "sender_id", "referenced_tweets"
    ],
    tweet_fields=[
        "id", "author_id", "created_at", "entities"
    ]
):
    ...

Does anyone have a solution?
Thank you for your help :slight_smile:

The first one with 1 tweet link shows a preview, and this is included as the referenced tweet, but it seems that 2 links doesn’t show a preview and gets treated as 2 links instead of 2 entries in referenced tweets.

Does it work if you specify dm_event.fields=attachments as a parameter? So you can see the two URLs? (In tweepy, add "attachments" to dm_event_fields I mean)

Hello,

Thank you for your reply.

I tried but that didn’t work :'(.

Code :

tweepy.Paginator(
    client.get_direct_message_events,
    max_results=100,
    limit=3,
    expansions=[
        "sender_id", "referenced_tweets.id", "participant_ids"
    ],
    user_fields=[
        "id", "username", "name"
    ],
    dm_event_fields=[
        "id", "created_at", "dm_conversation_id", "attachments",
        "participant_ids", "sender_id", "referenced_tweets"
    ],
    tweet_fields=[
        "id", "author_id", "created_at", "entities"
    ]
):

Result :

{
    "event_type": "MessageCreate",
    "dm_conversation_id": "123456789-987654321",
    "id": "160102...",
    "text": "(...) https://t.co/jm... https://t.co/d8...",
    "sender_id": "133712...",
    "created_at": "2022-12-09T01:08:47.000Z"
}
1 Like

Yeah, ideally I’d expect both to appear in referenced tweets, hope they change it!

It’s a new API so maybe they will, apart from these forums, the official place for requests is GitHub - twitterdev/open-evolution: Open evolution proposals for the Twitter API

Thank you for your reply.

Here you are : Tweets don’t always found from direct messages · Issue #32 · twitterdev/open-evolution · GitHub

2 Likes