x apiを使って特定のキーワードの過去24hの投稿を取得する方法は
- User
x apiを使って特定のキーワードの過去24hの投稿を取得する方法は
Assistant
X APIを使って過去24時間の投稿を取得するには、以下の方法があります。
Search Tweets エンドポイントを使用
X API v2の
GET /2/tweets/search/recentエンドポイントを使用します。このエンドポイントは過去7日間のツイートを検索できます。import requests from datetime import datetime, timedelta # 24時間前の時刻を計算 now = datetime.utcnow() yesterday = now - timedelta(hours=24) start_time = yesterday.strftime('%Y-%m-%dT%H:%M:%S.000Z') # APIリクエスト url = "https://api.twitter.com/2/tweets/search/recent" headers = { "Authorization": "Bearer YOUR_BEARER_TOKEN" } params = { "query": "your_keyword", "start_time": start_time, "max_results": 100, # 10-100の範囲 "tweet.fields": "created_at,author_id,public_metrics" } response = requests.get(url, headers=headers, params=params) tweets = response.json()重要なポイント
: パラメータで24時間前からの投稿を指定できます。ISO 8601形式(UTC)で指定する必要があります。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.