Setup
Put them in your environment or
.env; Data APIs covers the other ways.
Notes
- A bearer token reads public data. Publishing needs a user-context access token with the right scopes, minted through X’s OAuth 2.0 flow.
- Responses carry only default fields (id, text for posts; id, name, username for users): request more with post.fields and user.fields.
- Pagination is by next_token (search) or pagination_token (timelines) taken from meta in the previous answer.
- Access and rate limits depend on the developer account’s plan (see pricing_url).
Endpoints
Search posts from the last 7 days
- Only the last 7 days: older posts need the full-archive search, which is a higher access tier and not listed here.
- Without post.fields a post comes back as just id and text. Ask for public_metrics, created_at, author_id.
- Pages by meta.next_token. Reads are billed to the developer account’s X API plan.
Get a user by username
- Returns only id, name and username unless user.fields asks for more (description, public_metrics, created_at, verified …).