diff --git a/x-api/account-activity/migrate/aaa-to-xaa-migration.mdx b/x-api/account-activity/migrate/aaa-to-xaa-migration.mdx index db493a4ba..3ee398eb2 100644 --- a/x-api/account-activity/migrate/aaa-to-xaa-migration.mdx +++ b/x-api/account-activity/migrate/aaa-to-xaa-migration.mdx @@ -28,7 +28,7 @@ Contact your account manager with any questions. - **Granular subscriptions.** Instead of an all-or-nothing subscription per user, choose exactly which event types you want for each user, and narrow them further with [filter qualifiers](/x-api/activity/introduction#filter-qualifiers) such as `direction`, `post_id`, `conversation_type`, and `woeid`. You only receive, and process, the events you need. - **New event types.** XAA supports event families AAA never served, including encrypted XChat messages, profile updates, live broadcast start, end, and chat events, Spaces, paid subscriptions, and newly surfaced trends and Grok-curated news headlines filtered by keyword. See [Supported event types](/x-api/activity/introduction#supported-event-types). - **Webhook or streaming delivery.** Receive events on your existing webhook, over a [persistent HTTP stream](/x-api/activity/activity-stream), or both. The stream supports up to 5 minutes of backfill on connect and recovery of missed events with `start_time` and `end_time`. -- **Keep your webhook and your users' authorizations.** XAA uses the same [V2 Webhooks API](/x-api/webhooks/introduction), CRC checks, and signature headers as AAA, so you can point XAA subscriptions at the webhook you already use. XAA accepts the OAuth 1.0a user access tokens you already hold, so users don't need to re-authorize your app to migrate. +- **Keep your webhook and your users' authorizations.** XAA uses the same [V2 Webhooks API](/x-api/webhooks/introduction), CRC checks, and signature headers as AAA, so you can point XAA subscriptions at the webhook you already use. XAA accepts the OAuth 1.0a user access tokens you already hold, so users don't need to re-authorize your app to migrate. To subscribe to DM (`dm.*`) or X Chat (`chat.*`) events with OAuth 1.0a, your app needs the **"Read, Write and Direct Messages"** permission. - **OAuth 2.0 with fine-grained scopes.** XAA supports OAuth 2.0, so you can request only the scopes you need (for example `dm.read`, `like.read`, `block.read`, `mute.read`, `tweet.read`). OAuth 1.0a support in XAA will be deprecated soon, so plan to move your users to OAuth 2.0. - **Same replay window.** Recover events from the past 24 hours with [`POST /2/webhooks/replay`](/x-api/webhooks/create-replay-job-for-webhook), the same window as AAA replay. - **X API v2 data format.** Post and user objects match the rest of X API v2, with related objects in `includes`, so the same parsing code works across endpoints. @@ -161,7 +161,7 @@ XAA does not currently deliver two things AAA did: Posts from protected accounts Add support for the XAA envelope and v2 objects, and keep AAA parsing in place until cutover is complete. - Call [`POST /2/activity/subscriptions`](/x-api/activity/create-x-activity-subscription) once per user and event type, passing your existing `webhook_id`. Authenticate with the subscribed user's access token: either an OAuth 2.0 token with the matching scope, or the OAuth 1.0a token you already use for AAA. Public events can also be created with your app's bearer token. See [Event privacy and authentication](/x-api/activity/introduction#event-privacy-and-authentication). + Call [`POST /2/activity/subscriptions`](/x-api/activity/create-x-activity-subscription) once per user and event type, passing your existing `webhook_id`. Authenticate with the subscribed user's access token: either an OAuth 2.0 token with the matching scope, or the OAuth 1.0a token you already use for AAA. With OAuth 1.0a, `dm.*` and `chat.*` subscriptions need the **"Read, Write and Direct Messages"** app permission and return `403 oauth1-permissions` without it. Public events can also be created with your app's bearer token. See [Event privacy and authentication](/x-api/activity/introduction#event-privacy-and-authentication). Confirm XAA events are arriving for each migrated user. While both AAA and XAA subscriptions are active for a user, you receive each activity twice, once in each format. @@ -177,6 +177,10 @@ The following example creates XAA subscriptions for one user with the OAuth 1.0a OAuth 1.0a support in XAA will be deprecated soon. You can use your existing OAuth 1.0a tokens to migrate, but plan to move your users to OAuth 2.0. + +The `dm.*` event types in this example need an app with the **"Read, Write and Direct Messages"** permission. If your app has **"Read"** or **"Read and Write"**, those subscriptions return `403 oauth1-permissions`; remove them from the list or update the app permission and have users re-authorize. + + ```python import requests from requests_oauthlib import OAuth1 @@ -212,7 +216,7 @@ for event_type in EVENT_TYPES: Yes. XAA uses the same V2 Webhooks API as AAA. Pass your existing `webhook_id` when you create XAA subscriptions. CRC checks and signature verification work the same way. - Not to migrate. XAA accepts the OAuth 1.0a user access tokens you already use with AAA, and if you use managed migration, we migrate your existing subscriptions for you. OAuth 1.0a support in XAA will be deprecated soon, though, so plan to move your users to OAuth 2.0. + Not to migrate, as long as your app's OAuth 1.0a permission covers the events you need (`dm.*` and `chat.*` events need **"Read, Write and Direct Messages"**). XAA accepts the OAuth 1.0a user access tokens you already use with AAA, and if you use managed migration, we migrate your existing subscriptions for you. OAuth 1.0a support in XAA will be deprecated soon, though, so plan to move your users to OAuth 2.0. You can optionally upgrade your users to OAuth 2.0 without asking them to log in again. Use the [OAuth 1.0a token exchange](/fundamentals/authentication/oauth-2-0/oauth-1-0a-token-exchange) to swap each stored OAuth 1.0a access token and secret for an OAuth 2.0 access token and refresh token for the same user. diff --git a/x-api/activity/introduction.mdx b/x-api/activity/introduction.mdx index dda20f66b..e8d7bbe1c 100644 --- a/x-api/activity/introduction.mdx +++ b/x-api/activity/introduction.mdx @@ -337,7 +337,8 @@ Private events are activities that require explicit user consent through OAuth a - Broadcast chats (`broadcast.chat`, `broadcast.chat.remove`) — requires the `broadcast.read` scope **Authentication requirements for private events:** -- The user must authenticate your application via OAuth 2.0 +- The user must authenticate your application via OAuth 2.0 (OAuth 1.0a user tokens are also accepted) +- For chat (`chat.*`) and DM (`dm.*`) events with OAuth 1.0a, your app needs the **"Read, Write and Direct Messages"** permission; otherwise `POST /2/activity/subscriptions` returns `403 oauth1-permissions` - Your application must obtain appropriate OAuth scopes - The user must explicitly grant permission for your app to access these events - Subscriptions for private events can only be created for users who have authorized your application diff --git a/xchat/getting-started.mdx b/xchat/getting-started.mdx index 1823fec1c..736ca3b57 100644 --- a/xchat/getting-started.mdx +++ b/xchat/getting-started.mdx @@ -19,6 +19,7 @@ X Chat apps use two pieces together: - [Developer account](https://developer.x.com/en/portal/petition/essential/basic-info) and an app configured for OAuth 2.0 - User access token with `dm.read`, `dm.write`, `tweet.read`, and `users.read` +- OAuth 1.0a user tokens also work until January 31, 2027, if your app has the **"Read, Write and Direct Messages"** permission --- diff --git a/xchat/introduction.mdx b/xchat/introduction.mdx index bfdbc50dd..0b3801a90 100644 --- a/xchat/introduction.mdx +++ b/xchat/introduction.mdx @@ -44,7 +44,7 @@ Grouped under **API reference** in the sidebar, including: ## Auth notes -Use **OAuth 2.0 user context** with DM-related scopes (`dm.read`, `dm.write`, `users.read`, `tweet.read`, **`media.write` for both media uploads and downloads**, and `offline.access` for refresh tokens). X Chat activity for a user requires that user's authorization. Secure key backup configuration is returned on **your** public-key record (`juicebox_config` field); see [Getting Started](/xchat/getting-started) and the full scope matrix in [Migrate from Legacy DMs](/xchat/migrate-from-legacy-dms#2-authentication-and-oauth-20-scope-matrix). +Use **OAuth 2.0 user context** with DM-related scopes (`dm.read`, `dm.write`, `users.read`, `tweet.read`, **`media.write` for both media uploads and downloads**, and `offline.access` for refresh tokens). OAuth 1.0a user tokens also work on every X Chat endpoint until January 31, 2027, if your app has the **"Read, Write and Direct Messages"** permission (apps with Read or Read and Write get `403 oauth1-permissions`). X Chat activity for a user requires that user's authorization. Secure key backup configuration is returned on **your** public-key record (`juicebox_config` field); see [Getting Started](/xchat/getting-started) and the full scope matrix in [Migrate from Legacy DMs](/xchat/migrate-from-legacy-dms#2-authentication-and-oauth-20-scope-matrix). --- diff --git a/xchat/media.mdx b/xchat/media.mdx index e2faba3d9..35235c330 100644 --- a/xchat/media.mdx +++ b/xchat/media.mdx @@ -8,7 +8,7 @@ keywords: ["X Chat media", "encrypted images", "file attachments", "encrypt_file Images and other files are encrypted client-side with the Chat XDK (`encrypt_file` / `decrypt_file`), uploaded via the **`/2/chat/media/upload`** routes (sidebar **API reference → Media**), and referenced by **`media_hash_key`** inside `encrypt_message`. -**`media.write` is required for both uploads and downloads.** All four `/2/chat/media/*` routes — including `GET /2/chat/media/{conversation_id}/{media_hash_key}` — require the `media.write` OAuth 2.0 scope, not `dm.read`. +**`media.write` is required for both uploads and downloads.** All four `/2/chat/media/*` routes — including `GET /2/chat/media/{conversation_id}/{media_hash_key}` — require the `media.write` OAuth 2.0 scope, not `dm.read`. With OAuth 1.0a, your app needs the **"Read, Write and Direct Messages"** permission; **"Read and Write"** is not enough and returns `403 oauth1-permissions`. Use hyphenated conversation IDs in URL paths (`:` → `-`) and canonical colon IDs (`min:max` or `g…`) in upload JSON bodies. Prefer MIME and dimensions from **decrypted** bytes. Maximum encrypted file size is **100 MB**. diff --git a/xchat/migrate-from-legacy-dms.mdx b/xchat/migrate-from-legacy-dms.mdx index 7293cff61..08f074e26 100644 --- a/xchat/migrate-from-legacy-dms.mdx +++ b/xchat/migrate-from-legacy-dms.mdx @@ -104,9 +104,9 @@ Every `/2/chat/*` and `/2/users/*/public_keys` route requires **user-context aut - OAuth 1.0a user tokens **work with X Chat endpoints** during migration — including `GET` / `POST /2/users/{id}/public_keys` and `POST /2/activity/subscriptions` for chat events. Welcome-message endpoints currently require OAuth 2.0 (OAuth 1.0a support is being added). + OAuth 1.0a user tokens **work with every X Chat endpoint** during migration — including welcome messages, welcome-message rules, surveys, media upload and download, `GET` / `POST /2/users/{id}/public_keys`, and `POST /2/activity/subscriptions` for chat events. - - **Required app permission:** Configure **"Read, Write and Direct Messages"** permissions, otherwise routes return `403 oauth1-permissions`. Tokens keep the permissions they were originally granted: if your app already has this permission, existing tokens keep working; if you change the permission, users must re-authorize. + - **Required app permission:** Configure **"Read, Write and Direct Messages"** permissions. Every X Chat route, including send, typing, read and unread, group creation, and media, requires it: apps with **"Read"** or **"Read and Write"** get `403 oauth1-permissions`. Tokens keep the permissions they were originally granted: if your app already has this permission, existing tokens keep working; if you change the permission, users must re-authorize. - **`chat-xdk` is auth-agnostic:** The Chat XDK only encrypts, decrypts, and signs locally — it never calls the X API with your token, so you can sign HTTP requests with either OAuth 1.0a or OAuth 2.0. - **Plan your move before January 31, 2027:** OAuth 1.0a retires on **January 31, 2027**. Use the [OAuth 1.0a to OAuth 2.0 token exchange](/fundamentals/authentication/oauth-2-0/oauth-1-0a-token-exchange) to move existing users without a consent screen: @@ -147,7 +147,7 @@ Every `/2/chat/*` and `/2/users/*/public_keys` route requires **user-context aut | `DELETE /1.1/direct_messages/events/destroy.json` | `POST /2/chat/conversations/{id}/messages/delete` | | `POST /1.1/direct_messages/indicate_typing.json` | `POST /2/chat/conversations/{id}/typing` (empty body) | | `POST /1.1/direct_messages/mark_read.json` | `POST /2/chat/conversations/{id}/read` (empty body marks up to newest; pass `action_signatures` to target a specific event — fields like `seen_until_sequence_id` are ignored) | - | `direct_messages/welcome_messages/*` & surveys | X Chat versions exist in v2 (welcome-message endpoints currently require OAuth 2.0; OAuth 1.0a support is being added). Contact your X account representative for v2 partner onboarding. | + | `direct_messages/welcome_messages/*` & surveys | X Chat versions exist in v2 and accept OAuth 2.0 or OAuth 1.0a user tokens (OAuth 1.0a needs **"Read, Write and Direct Messages"**). Contact your X account representative for v2 partner onboarding. | | `custom_profiles/*` | *No equivalent* | | `POST /1.1/media/upload.json` (`media_category=dm_*`) & `GET ton.twitter.com/1.1/ton/data/dm/…` | `POST /2/chat/media/upload/initialize` → `/{id}/append` → `/{id}/finalize` and `GET /2/chat/media/{conversation_id}/{media_hash_key}` | @@ -178,7 +178,7 @@ Every `/2/chat/*` and `/2/users/*/public_keys` route requires **user-context aut | `CRUD /2/webhooks` & `POST /2/webhooks/replay` | Unchanged (set `webhook_id` on your subscription), or stream with `GET /2/activity/stream` (app Bearer token; run one consumer per app) | - - **Auth:** `POST /2/activity/subscriptions` accepts both OAuth 2.0 user tokens (`dm.read`) and OAuth 1.0a user tokens (**"Read, Write and Direct Messages"**) for `chat.*` events. + - **Auth:** `POST /2/activity/subscriptions` accepts both OAuth 2.0 user tokens (`dm.read`) and OAuth 1.0a user tokens (**"Read, Write and Direct Messages"**) for `chat.*` events. OAuth 1.0a tokens without that permission get `403 oauth1-permissions` when subscribing to `chat.*` or `dm.*` events. - **Group joins:** Subscribe to `chat.conversation.join` so bots learn when added to a group and receive the group conversation key. - **During cutover:** Unencrypted conversations still arrive as `dm.received` — subscribe to both `dm.received` and `chat.received` and deduplicate until cutover completes. - **Sender profiles:** Chat events currently carry user IDs only, not names or profiles. Look up profiles with `GET /2/users?ids=...` or `GET /2/chat/conversations?expansions=participant_ids&user.fields=...` and cache by user ID (`includes.users` hydration is being added to chat events). @@ -492,7 +492,7 @@ For SDK-specific cryptography, backup recovery, and decryption issues, see [Fix - No. OAuth 1.0a user tokens work with the X Chat endpoints, including the endpoints that look up and register a user's public keys. Welcome-message endpoints currently require OAuth 2.0 (OAuth 1.0a support is being added). App-Only Bearer tokens do not work on X Chat endpoints, so use user-context tokens. + No. OAuth 1.0a user tokens work with the X Chat endpoints, including welcome messages, surveys, and the endpoints that look up and register a user's public keys. Your app needs the **"Read, Write and Direct Messages"** permission. App-Only Bearer tokens do not work on X Chat endpoints, so use user-context tokens. OAuth 1.0a itself retires on **January 31, 2027**, so plan your move to OAuth 2.0 before then. The [OAuth 1.0a to OAuth 2.0 token exchange](/fundamentals/authentication/oauth-2-0/oauth-1-0a-token-exchange) moves existing users with DM permission over without asking them to reconnect. @@ -588,7 +588,7 @@ For SDK-specific cryptography, backup recovery, and decryption issues, see [Fix - Yes. `POST /2/activity/subscriptions` accepts OAuth 1.0a user tokens for chat events if the app has the **"Read, Write and Direct Messages"** permission. With OAuth 2.0, the token needs the `dm.read` scope. + Yes. `POST /2/activity/subscriptions` accepts OAuth 1.0a user tokens for chat events if the app has the **"Read, Write and Direct Messages"** permission (without it, `chat.*` and `dm.*` subscriptions return `403 oauth1-permissions`). With OAuth 2.0, the token needs the `dm.read` scope. @@ -610,7 +610,7 @@ For SDK-specific cryptography, backup recovery, and decryption issues, see [Fix X Chat has its own encrypted media upload and download endpoints (see [Media](/xchat/media)). Chat media downloads are encrypted and must be decrypted with `chat-xdk`; with OAuth 2.0, downloads require the `media.write` scope. Legacy DM media IDs do not work on X Chat media endpoints and return `404`. - Welcome messages and surveys also have X Chat versions in the API. Welcome-message endpoints currently require OAuth 2.0 (OAuth 1.0a support is being added). + Welcome messages and surveys also have X Chat versions in the API. They accept OAuth 2.0 and OAuth 1.0a user tokens; with OAuth 1.0a, your app needs the **"Read, Write and Direct Messages"** permission. diff --git a/xchat/real-time-events.mdx b/xchat/real-time-events.mdx index fe2f2a70d..0cede28a5 100644 --- a/xchat/real-time-events.mdx +++ b/xchat/real-time-events.mdx @@ -43,7 +43,7 @@ Typing indicators and read receipts no longer arrive as separate webhook types - `PUT /2/activity/subscriptions/{subscription_id}`: update - `DELETE /2/activity/subscriptions/{subscription_id}` or `DELETE /2/activity/subscriptions?ids=`: delete -Request bodies and required scopes are defined in the OpenAPI operation for each route. Creating an X Activity API (XAA) subscription requires **user-context authorization** (OAuth 2.0 user context with `dm.read` for chat events) for the user whose activity you monitor. +Request bodies and required scopes are defined in the OpenAPI operation for each route. Creating an X Activity API (XAA) subscription requires **user-context authorization** (OAuth 2.0 user context with `dm.read` for chat events, or an OAuth 1.0a user token from an app with the **"Read, Write and Direct Messages"** permission) for the user whose activity you monitor. **Webhooks:** if you terminate events on your HTTPS endpoint, register a webhook with `POST /2/webhooks`, pass CRC challenges, then create your activity subscriptions with `POST /2/activity/subscriptions`, referencing your `webhook_id` (see Webhooks and Activity operations in OpenAPI). Use `POST /2/webhooks/replay` to replay missed webhook deliveries. Note that `payload.conversation_id` arrives in canonical colon form (`min:max` for 1:1s) — replace `:` with `-` before placing it in URL paths. diff --git a/xchat/troubleshooting.mdx b/xchat/troubleshooting.mdx index a3bfd20df..26819551e 100644 --- a/xchat/troubleshooting.mdx +++ b/xchat/troubleshooting.mdx @@ -283,6 +283,7 @@ Every state-changing chat call (adding or rotating conversation keys, creating a |:-------------|:------|:----| | `400` `INVALID_IDENTITY_KEY_PAIR` (`POST /2/chat/conversations/{id}/keys`) | One or more participant keys used an outdated `public_key_version`. | Re-fetch `GET /2/users/{id}/public_keys` (or `GET /2/users/public_keys`), rebuild with `prepare_conversation_key_change`, and retry once. Do not cache public key versions indefinitely. | | `403` `UNAUTHORIZED_REQUESTING_USER` (`POST /2/chat/conversations/{id}/keys`) or `403` `recipient-not-messageable` (`POST /2/chat/conversations/{id}/messages`) | Permanent refusal: the recipient has not set up X Chat keys, does not follow you / has not accepted a message request, or their settings block DMs. | Check `GET /2/users/{id}/public_keys` before initializing keys and treat `403` as permanent — do not retry in a loop. | +| `403` `oauth1-permissions` | An OAuth 1.0a user token from an app without the **"Read, Write and Direct Messages"** permission. Every X Chat route, including media, and `chat.*` / `dm.*` activity subscriptions require it. | Set the app permission to **"Read, Write and Direct Messages"** and have users re-authorize (tokens keep the permission they were issued with), or move to OAuth 2.0. | | `400` `xchat-setup-required` / `recipient-xchat-setup-required` | The sender or recipient has not registered X Chat public keys yet. | Ensure the sending account completed key setup, and verify recipients have public keys before sending. | | `400` `ContentsTooLarge` / validation error on send | Encrypted message payloads are capped at **20 KB** (~11,000 UTF-8 plaintext bytes). | Truncate or split long messages before calling `encrypt_message`. | | `404` on `GET /2/chat/media/{id}/{media_hash_key}` | The attachment was deleted, expired, or the `media_hash_key` is invalid (for example, a legacy DM media ID rather than an encrypted X Chat `media_hash_key`). | Treat `404` as permanent — do not re-queue. |