---
title: "X API OAuth 2.0 token lifetimes"
description: "X OAuth 2.0 tokens: access tokens last two hours, refresh tokens come only with offline.access, and authorization codes have a 30-second limit. When PubNio refreshes."
---

> Documentation Index
> Fetch the complete documentation index at: https://pubnio.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# X API OAuth 2.0 token lifetimes

An X OAuth 2.0 access token stays valid for two hours. X issues a refresh token only when the app asks for offline.access. The authorization code has a 30-second time limit, so exchange it at once. (Checked 2026-12-05.)

## Facts

| Fact                         | Official value           | Source                                                                                                                                      | Checked    |
| ---------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| Access token                 | Two hours                | [X API: OAuth 2.0 Authorization Code Flow with PKCE](https://docs.x.com/resources/fundamentals/authentication/oauth-2-0/authorization-code) | 2026-12-05 |
| Refresh token issued         | Only with offline.access | [X API: OAuth 2.0 Authorization Code Flow with PKCE](https://docs.x.com/resources/fundamentals/authentication/oauth-2-0/authorization-code) | 2026-12-05 |
| Authorization code (seconds) | 30                       | [X API: OAuth 2.0 Authorization Code Flow with PKCE](https://docs.x.com/resources/fundamentals/authentication/oauth-2-0/authorization-code) | 2026-12-05 |

## Where official docs disagree

The official pages read for this page agree on every value above.

## What PubNio enforces

- PubNio asks for offline.access and refreshes an X token 10 minutes before it expires.

## Read the live value

- [`GET /api/v1/integrations/accounts/{accountId}`](https://pubnio.com/api/v1/docs#tag/integrations/GET/api/v1/integrations/accounts/{accountId}) reports `needs_reconnect` with reason
  `token_expired` when a X token can no longer be used; [`POST /api/v1/integrations/accounts/{accountId}/reconnect`](https://pubnio.com/api/v1/docs#tag/integrations/POST/api/v1/integrations/accounts/{accountId}/reconnect) keeps the account ID.

## Related errors

- A provider 401 becomes an `auth` provider error and a 403 a `permission` error; neither is retried.
- [X error codes](https://pubnio.com/docs/errors/x/) lists the errors PubNio returns for X and how to fix each.

## Limits

- PubNio does not migrate OAuth 1.0a user tokens; X accounts connect with OAuth 2.0.

## Sources

- [X API: OAuth 2.0 Authorization Code Flow with PKCE](https://docs.x.com/resources/fundamentals/authentication/oauth-2-0/authorization-code), checked 2026-12-05

  ```text
  will only stay valid for two hours unless you’ve used the `offline.access` scope.
  an OAuth 2.0 refresh token will be issued.
  The auth_code has a time limit of 30 seconds
  ```

- [X API: Apps](https://docs.x.com/resources/fundamentals/developer-apps), checked 2026-12-05

  ```text
  scheduled to be retired on January 31, 2027.
  ```

## Related

- [Posting limits](https://pubnio.com/docs/providers/x/limits/)
- [Rate limits and quota](https://pubnio.com/docs/providers/x/quota/)
- [Scopes and permissions](https://pubnio.com/docs/providers/x/scopes/)
- [App review and access](https://pubnio.com/docs/providers/x/app-review/)
- [Media requirements](https://pubnio.com/docs/providers/x/media/)
- [API versions](https://pubnio.com/docs/providers/x/versioning/)
- [X error codes](https://pubnio.com/docs/errors/x/)
- [Publishing to X](https://pubnio.com/docs/networks/x/)
- [Provider API explainers](https://pubnio.com/docs/providers/)

Source: https://pubnio.com/docs/providers/x/tokens/index.mdx
