APIYard
Back to APIs
SocialBearer TokenFree tier

X (Twitter) API v2

Access tweets, users, timelines, trends, and the social graph via X's v2 API — search recent tweets, post on behalf of users, and stream real-time data.

Base URL

https://api.twitter.com/2
tweetsuserstimelinesearchOAuth 2.0

Endpoints

GET/tweets/search/recent

Search for recent tweets matching a query.

const response = await fetch("https://api.twitter.com/2/tweets/search/recent?query=%23buildinpublic&tweet.fields=created_at,author_id&max_results=10", {
  method: "GET",
  headers: {
  "Content-Type": "application/json",
  "Authorization": "Bearer YOUR_ACCESS_TOKEN"
  }
});

const data = await response.json();
console.log(data);

Response Preview

{
  "data": [{
    "id": "1234567890",
    "text": "Launched v2 today! #buildinpublic",
    "created_at": "2024-05-01T12:00:00Z",
    "author_id": "98765"
  }],
  "meta": { "result_count": 10, "newest_id": "1234567890" }
}