Documentation Index
Fetch the complete documentation index at: https://generaltranslation.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
이 가이드는 필터 규칙과 일치하는 실시간 포스트를 받기 위해 필터링된 스트림에 연결하는 방법을 설명합니다.
사전 준비 사항시작하기 전에 다음이 필요합니다:
- 개발자 계정
- 개발자 콘솔의 “Keys and tokens”에서 확인할 수 있는 App의 Bearer 토큰
필터 규칙 만들기
규칙은 어떤 포스트를 받을지 정의합니다. 연산자를 사용해 키워드, 해시태그, 사용자 등을 기준으로 일치시킬 수 있습니다.예시 규칙: “cat”이 포함되어 있고 이미지가 있는 포스트와 일치:규칙 만들기
규칙 구문과 연산자에 대해 알아보세요
스트림에 규칙을 추가하세요
규칙 엔드포인트를 사용해 규칙을 추가하세요. 어떤 규칙이 각 게시물과 일치했는지 식별할 수 있도록 tag를 포함하세요:curl -X POST "https://api.x.com/2/tweets/search/stream/rules" \
-H "Authorization: Bearer $BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"add": [
{"value": "cat has:images", "tag": "cats with images"}
]
}'
응답:{
"data": [
{
"id": "1273026480692322304",
"value": "cat has:images",
"tag": "cats with images"
}
],
"meta": {
"sent": "2024-01-15T10:30:00.000Z",
"summary": {
"created": 1,
"not_created": 0,
"valid": 1,
"invalid": 0
}
}
}
규칙을 확인하세요
모든 활성 규칙을 나열하여 규칙이 추가되었는지 확인하세요:curl "https://api.x.com/2/tweets/search/stream/rules" \
-H "Authorization: Bearer $BEARER_TOKEN"
스트림에 연결하기
일치하는 포스트를 받기 위해 지속 연결을 설정합니다:curl "https://api.x.com/2/tweets/search/stream?\
tweet.fields=created_at,author_id&\
expansions=author_id&\
user.fields=username" \
-H "Authorization: Bearer $BEARER_TOKEN"
수신된 포스트 처리
일치하는 포스트 스트림(JSON 객체):{
"data": {
"id": "1234567890",
"text": "Look at this cute cat! 🐱",
"author_id": "9876543210",
"created_at": "2024-01-15T10:35:00.000Z",
"edit_history_tweet_ids": ["1234567890"]
},
"includes": {
"users": [
{
"id": "9876543210",
"username": "catperson"
}
]
},
"matching_rules": [
{
"id": "1273026480692322304",
"tag": "cats with images"
}
]
}
matching_rules 배열은 여러분이 정의한 태그를 기준으로 어떤 규칙이 이 게시물에 매칭되었는지 보여 줍니다.
규칙 삭제(선택 사항)
ID로 규칙 삭제:curl -X POST "https://api.x.com/2/tweets/search/stream/rules" \
-H "Authorization: Bearer $BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"delete": {
"ids": ["1273026480692322304"]
}
}'
스트림은 20초마다 빈 줄(\r\n)을 전송합니다. 20초 동안 데이터나 keep-alive 신호를 받지 못하면 다시 연결하세요.
연결을 종료하려면 Ctrl+C를 누르거나 터미널 창을 닫으세요.
App당 하나의 연결만 허용됩니다. 새 연결을 열면 기존 연결은 자동으로 종료됩니다.