메인 콘텐츠로 건너뛰기

X API를 사용한 대화 스레드

X에서 대화가 전개되는 방식을 보면, 하나의 게시물이 여러 대화 스레드를 촉발할 수 있으며, 더 많은 사람이 참여할수록 각 스레드는 길이와 복잡성이 증가할 수 있습니다. 게시물 간의 관계를 식별하고 대화 스레드를 이해하는 기능은 X API v2의 페이로드 및 검색 기능에 포함되어 있습니다. 게시물에 대한 응답(답글)으로 게시물이 올라오거나, 답글에 대한 추가 응답이 이어지는 경우, 이제 각 답글에는 해당 대화를 시작한 원본 게시물의 게시물 ID와 일치하는 conversation_id가 정의됩니다. 특정 게시물에 대한 답글과 그 답글에 대한 추가 답글은 모두 단일 원본 게시물에서 파생된 하나의 대화에 포함됩니다. 생성되는 답글 스레드가 얼마나 많든, 모두 대화를 촉발한 원본 게시물과 동일한 conversation_id를 공유합니다. X API v2를 사용하면 전체 대화 스레드를 조회하고 재구성할 수 있어, 어떤 이야기가 오가는지와 대화 및 아이디어가 어떻게 전개되는지 파악할 수 있습니다.

예시 대화 스레드

아래는 다섯 사람이 참여한 예시 대화 스레드로, 답글에 대한 답글 하나를 포함합니다.
{
  "data": [
    {
      "conversation_id": "1279944223114900000",
      "in_reply_to_user_id": "1102323333",
      "author_id": "63044444",
      "created_at": "2020-07-06T15:58:10.000Z",
      "id": "1280169177479744444",
      "referenced_tweets": [
        {
          "type": "replied_to",
          "id": "1280155225706433333"
        }
      ],
      "text": "@ThirdPerson333 @OriginalPerson000 세 번째 답글에 답글!",
    },
    {
      "conversation_id": "1279944223114900000",
      "in_reply_to_user_id": "3001960000",
      "author_id": "1102323333",
      "created_at": "2020-07-06T15:02:44.000Z",
      "id": "1280155225706433333",
      "referenced_tweets": [
        {
          "type": "replied_to",
          "id": "1279944223114900000"
        }
      ],
      "text": "@OriginalPerson000 세 번째 답글",
    },
    {
      "conversation_id": "1279944223114900000",
      "in_reply_to_user_id": "3001960000",
      "author_id": "199562222",
      "created_at": "2020-07-06T15:02:36.000Z",
      "id": "1280155190306340864",
      "referenced_tweets": [
        {
          "type": "replied_to",
          "id": "1279944223114900000"
        }
      ],
      "text": "@OriginalPerson000 두 번째 답글",
    }
  ],
  "includes": {
    "users": [
      {
        "name": "원 작성자",
        "id": "3001960000",
        "username": "OriginalPerson000"
      },
      {
        "name": "첫 번째 사용자"
        "id": "179201111",
        "username": "FirstPerson111"
      }
    ]
  },
  "meta": {
    "newest_id": "1280169177479744444",
    "oldest_id": "1279945722494811111",
    "result_count": 4
  }
}
tweet.fields 매개변수로 conversation_id 가져오기 v2 엔드포인트에서 반환되는 모든 게시물에 대해 conversation_id를 받으려면 요청 매개변수에 tweet.fields=conversation_id를 추가하세요. conversation_id는 항상 해당 대화의 답글 스레드에서 원본 게시물의 게시물 ID입니다. 이전 답글 스레드에서 파생된 스레드를 포함해 동일한 답글 스레드에 속한 모든 게시물은 동일한 conversation_id를 갖습니다.

conversation_id 매개변수를 사용한 요청

curl --request GET \
  --url 'https://api.x.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 $ACCESS_TOKEN'

응답

{
  "data": [
    {
      "id": "1225917697675886593",
      "text": "@TwitterEng *에헴* https://t.co/aroJHt2zQ1",
      "created_at": "2020-02-07T23:02:10.000Z",
      "author_id": "2244994945",
      "in_reply_to_user_id": "6844292",
      "conversation_id": "1225912275971657728",
      "referenced_tweets": [
        {
          "type": "인용",
          "id": "1200517737669378053"
        },
        {
          "type": "답글 대상",
          "id": "1225912275971657728"
        }
      ]
    }
  ],
  "includes": {
    "users": [
      {
        "username": "TwitterDev",
        "name": "Twitter Dev",
        "id": "2244994945"
      },
      {
        "username": "TwitterEng",
        "name": "Twitter Engineering",
        "id": "6844292"
      }
    ],
    "tweets": [
      {
        "id": "1200517737669378053",
        "text": "| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|\n             금요일에는            \n             프로덕션에            \n             배포하지 마라            \n|___________| \n(\\__/)",
        "created_at": "2019-11-29T20:51:47.000Z",
        "author_id": "2244994945",
        "conversation_id": "1200517737669378053"
      }
    ]
  }
}

conversation_id를 필터 연산자로 사용하기

conversation_id는 최근 검색에서 검색 쿼리 매개변수로 사용하거나, filtered stream을 위한 규칙 내 연산자로 사용할 수 있습니다. 이를 통해 filtered stream에서는 실시간으로, search Tweets에서는 최신순(내림차순)으로 정렬된 전체 대화 스레드를 구성하는 게시물을 반환합니다. 또한 이 연산자를 Posts counts와 함께 사용하여 해당 대화에 포함된 게시물 수를 조회할 수 있습니다.

conversation_id로 조회하는 요청

curl --request GET \
  --url 'https://api.x.com/2/tweets/search/recent?query=conversation_id:1279940000004973111&tweet.fields=in_reply_to_user_id,author_id,created_at,conversation_id' \
  --header 'Authorization: Bearer $ACCESS_TOKEN'

응답

참고: 검색된 게시물의 결과는 최신순으로 표시됩니다.
{
  "data": [
    {
      "id": "1280169000000704333",
      "text": "@attributeisland @iterationjoe 정말 아름다운 생물이네요! 즐거운 #seaturtleweek 되세요",
      "conversation_id": "1279940000004973111",
      "public_metrics": {
        "retweet_count": 0,
        "reply_count": 0,
        "like_count": 7,
        "quote_count": 0
      }
    }
  ],
  "meta": {
    "newest_id": "1280169000000704333",
    "oldest_id": "1279940000004973111",
    "result_count": 5
  }
}