최근 Post counts 가져오기
1
쿼리 작성
recent search와 동일한 쿼리 구문을 사용합니다. 예를 들어 @XDevelopers의 게시물 수를 세려면:
from:XDevelopers
2
요청 보내기
cURL
curl "https://api.x.com/2/tweets/counts/recent?\
query=from%3AXDevelopers&\
granularity=day" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# Get recent Post counts
response = client.posts.count_recent(
query="from:XDevelopers",
granularity="day"
)
for bucket in response.data:
print(f"{bucket.start}: {bucket.tweet_count} Posts")
print(f"Total: {response.meta.total_tweet_count}")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// Get recent Post counts
const response = await client.posts.countRecent({
query: "from:XDevelopers",
granularity: "day",
});
response.data?.forEach((bucket) => {
console.log(`${bucket.start}: ${bucket.tweet_count} Posts`);
});
console.log(`Total: ${response.meta?.total_tweet_count}`);
3
응답 확인
{
"data": [
{
"end": "2024-01-16T00:00:00.000Z",
"start": "2024-01-15T00:00:00.000Z",
"tweet_count": 5
},
{
"end": "2024-01-17T00:00:00.000Z",
"start": "2024-01-16T00:00:00.000Z",
"tweet_count": 3
},
{
"end": "2024-01-18T00:00:00.000Z",
"start": "2024-01-17T00:00:00.000Z",
"tweet_count": 8
}
],
"meta": {
"total_tweet_count": 16
}
}
Granularity 옵션
카운트가 어떻게 그룹화되는지 제어합니다:| Granularity | Description |
|---|---|
minute | 분 단위 카운트 |
hour | 시간 단위 카운트 (기본값) |
day | 일 단위 카운트 |
cURL
# Get hourly counts
curl "https://api.x.com/2/tweets/counts/recent?\
query=python%20lang%3Aen&\
granularity=hour" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# Get hourly counts
response = client.posts.count_recent(
query="python lang:en",
granularity="hour"
)
for bucket in response.data:
print(f"{bucket.start}: {bucket.tweet_count}")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// Get hourly counts
const response = await client.posts.countRecent({
query: "python lang:en",
granularity: "hour",
});
response.data?.forEach((bucket) => {
console.log(`${bucket.start}: ${bucket.tweet_count}`);
});
시간 범위로 필터링
카운트를 특정 기간으로 한정합니다:cURL
curl "https://api.x.com/2/tweets/counts/recent?\
query=from%3AXDevelopers&\
start_time=2024-01-10T00%3A00%3A00Z&\
end_time=2024-01-15T00%3A00%3A00Z&\
granularity=day" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# Get counts for a specific time range
response = client.posts.count_recent(
query="from:XDevelopers",
start_time="2024-01-10T00:00:00Z",
end_time="2024-01-15T00:00:00Z",
granularity="day"
)
print(f"Total Posts: {response.meta.total_tweet_count}")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// Get counts for a specific time range
const response = await client.posts.countRecent({
query: "from:XDevelopers",
startTime: "2024-01-10T00:00:00Z",
endTime: "2024-01-15T00:00:00Z",
granularity: "day",
});
console.log(`Total Posts: ${response.meta?.total_tweet_count}`);
공통 파라미터
| Parameter | Description | Default |
|---|---|---|
query | 검색 쿼리 (필수) | — |
granularity | 시간 버킷 크기 | hour |
start_time | 가장 오래된 타임스탬프 (ISO 8601) | 7일 전 |
end_time | 가장 최근 타임스탬프 (ISO 8601) | 현재 |
다음 단계
Full-archive counts
과거 Post counts 가져오기
쿼리 작성
쿼리 구문 마스터하기
API 레퍼런스
전체 엔드포인트 문서