簡體   English   中英

使用最新的 Twitter REST API v1.1 獲取 Twitter 對話是否有任何解決辦法

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

我正在處理一個需要檢索 Twitter 用戶對話的項目。 例如,我想獲得BBC World Service這條推文的所有回復。 使用REST API v1.1,我可以獲得 Twitter 用戶的時間線(推文、轉發推文)。 但是我沒有找到任何文檔/工作來獲取特定推文的回復。 是否有任何解決方法來獲取特定推文的回復?

沒有API 調用來獲取對特定推文的回復。 但是,您可以作弊!

使用Search API,您可以構建一個搜索查詢,它是:

  • 回復@bbcworldservice
  • 發生推文發布后。
  • (可選)特定日期/時間之前。

所以,在這種情況下,就像

https://api.twitter.com/1.1/search/tweets.json?
    q=%23bbcworldservice&
    since_id=489366839953489920&
    count=100

您將獲得推文列表(最多 100 個)。 然后,您需要在它們中搜索in_reply_to_status_id_str並查看它是否與您要查找的狀態匹配。

TwitterAPI v2 允許您在搜索中僅使用 session_id 來檢索整個對話線程。 (在 v1.1 中,您必須編寫自定義代碼來構建它)

對給定推文的回復以及對這些回復的回復都包含在源自單個原始推文的對話中。 無論結果有多少回復線程,它們都會與引發對話的原始推文共享一個共同的對話 ID。 使用 Twitter API v2,您可以檢索和重建整個對話線程,以便您可以更好地理解正在說什么,以及對話和想法是如何演變的。

例子:

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' 

響應會像

{
    "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"
            }
        ]
    }
}

有關更多信息,請查看 Twitter API 對話

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM