open-evolution icon indicating copy to clipboard operation
open-evolution copied to clipboard

Tweets don’t always found from direct messages

Open steven-douilliet opened this issue 1 year ago • 1 comments

Context

Twitter API version : v2

Endpoint : GET /2/dm_events

Library : Tweepy library

I want to retrieve the tweets from direct messages sent by participants. Below my 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"
    ]
)

The issue

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

When a participant sends a tweet link, it can be shows in two ways :

  1. The link is displayed and shows a preview (if not sensitve) and this is included as referenced tweet :
{
    "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"
}
  1. Sometimes the link is displayed twice and no tweet is found whereas a tweet URL is present:
{
    "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"
}

steven-douilliet avatar Dec 12 '22 18:12 steven-douilliet