Is there any work around on fetching twitter conversations using latest Twitter REST API v1.1

后端 未结 2 1420
我寻月下人不归
我寻月下人不归 2020-12-28 11:31

I am working on a project where the conversation of a twitter user needs to be retrieved. For example i want to get all the replies of this tweet of BBC World Service. Using

2条回答
  •  一整个雨季
    2020-12-28 11:47

    The TwitterAPI v2 allows you to retrieve the entire conversation thread using just the conversation_id in search. (In v1.1 you had to write custom code to build it)

    Replies to a given Tweet, as well as replies to those replies, are all included in the conversation stemming from the single original Tweet. Regardless of how many reply threads result, they will all share a common conversation_id to the original Tweet that sparked the conversation. Using the Twitter API v2, you have the ability to retrieve and reconstruct an entire conversation thread, so that you can better understand what is being said, and how conversations and ideas evolve.

    Example:

    curl --request GET \
      --url 'https://api.twitter.com/2/tweets?ids=1225917697675886593&tweet.fields=author_id,conversation_id,created_at,in_reply_to_user_id,referenced_tweets&expansions=author_id,in_reply_to_user_id,referenced_tweets.id&user.fields=name,username' \
      --header 'Authorization: Bearer $BEARER_TOKEN' 
    

    Response will be like

    {
        "data": [
            {
                "id": "1225917697675886593",
                "text": "@TwitterEng",
                "created_at": "2020-02-07T23:02:10.000Z",
                "author_id": "2244994945",
                "in_reply_to_user_id": "6844292",
                "conversation_id": "1225912275971657728",
                "referenced_tweets": [
                    {
                        "type": "quoted",
                        "id": "1200517737669378053"
                    },
                    {
                        "type": "replied_to",
                        "id": "1225912275971657728"
                    }
                ]
            }
        ],
        "includes": {
            "users": [
                {
                    "username": "TwitterDev",
                    "name": "Twitter Dev",
                    "id": "2244994945"
                },
                {
                    "username": "TwitterEng",
                    "name": "Twitter Engineering",
                    "id": "6844292"
                }
            ],
            "tweets": [
                {
                    "id": "1200517737669378053",
                    "text": "| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|\n             don't push            \n             to prod on            \n               Fridays                  \n|___________| \n(\\__/)  ||\n(•ㅅ•) ||\n/   づ",
                    "created_at": "2019-11-29T20:51:47.000Z",
                    "author_id": "2244994945",
                    "conversation_id": "1200517737669378053"
                },
                {
                    "id": "1225912275971657728",
                    "text": "Note to self: Don't deploy on Fridays",
                    "created_at": "2020-02-07T22:40:37.000Z",
                    "author_id": "6844292",
                    "conversation_id": "1225912275971657728"
                }
            ]
        }
    }
    

    For more info checkout twitter API Conversation

提交回复
热议问题