v2 Account Activity API 迁移指南
变更摘要
- API 格式:endpoint 使用 /2/account_activity/ 基础路径替代 /1.1/account_activity/。
- Webhook 管理:Webhook 的创建、列表、验证(CRC)和删除由 V2 Webhooks API 处理。
- 认证:V2 endpoint 需要下列其一:
- OAuthUser(三方 OAuth)用于用户级操作(例如订阅用户)。
- OAuth2 App Only(OAuth 2.0 Bearer Token)用于应用级操作(例如列出/删除订阅)。
- V1.1 采用多种方式,常见为 OAuth 1.0a。
- Endpoint 映射:
V1.1 Endpoint | V2 等效项 / 操作 | 备注 |
---|---|---|
POST /1.1/account_activity/webhooks.json?url=<URL> | POST /2/webhooks | Docs。需要 OAuth2AppOnly。 |
GET /1.1/account_activity/webhooks.json | GET /2/webhooks | Docs。需要 OAuth2AppOnly。 |
PUT /1.1/account_activity/webhooks/:webhook_id.json | PUT /2/webhooks/:webhook_id | 触发 CRC。Docs。需要 OAuth2AppOnly。 |
DELETE /1.1/account_activity/webhooks/:webhook_id.json | DELETE /2/webhooks/:webhook_id | Docs。需要 OAuth2AppOnly。 |
POST /1.1/account_activity/webhooks/:webhook_id/subscriptions/all.json | POST /2/account_activity/webhooks/:webhook_id/subscriptions/all | 需要 OAuthUser。 |
GET /1.1/account_activity/subscriptions/count.json | GET /2/account_activity/subscriptions/count | 需要 OAuth2AppOnly。 |
GET /1.1/account_activity/webhooks/:webhook_id/subscriptions/all.json | GET /2/account_activity/webhooks/:webhook_id/subscriptions/all | 需要 OAuthUser。 |
GET /1.1/account_activity/webhooks/:webhook_id/subscriptions/all/list.json | GET /2/account_activity/webhooks/:webhook_id/subscriptions/all/list | 需要 OAuth2AppOnly。 |
DELETE /1.1/account_activity/webhooks/:webhook_id/subscriptions/:user_id/all | DELETE /2/account_activity/webhooks/:webhook_id/subscriptions/:user_id/all | 需要 OAuth2AppOnly。 |
DELETE /1.1/account_activity/webhooks/:webhook_id/subscriptions/all | 已弃用 / 无直接等效项 | 逐个删除,或通过 DELETE /2/webhooks/:webhook_id 移除该 webhook。 |
- 响应格式:请在 AAAPI 文档中查看成功与错误响应结构。
如何迁移
- 选择套餐:
- 为 Account Activity API 访问选择 Enterprise 或 Pro 套餐,需考虑:
- 所需 webhook 数量。
- 当前/预期的订阅数或已授权用户数。
- X 客户端应用数量。
- 期望的支持级别(社区论坛 vs. 企业托管的一对一支持)。
- 定价详情(Enterprise 请联系销售)。
- 为 Account Activity API 访问选择 Enterprise 或 Pro 套餐,需考虑:
- 将身份验证更新为 OAuth 2.0:
- 确保你的 X App 具有“读取、写入和访问私信”的权限。
- 将 V2 endpoints 更新为使用 OAuth 2.0。如作用域发生变化,请重新授权用户。
- 使用开发者门户管理:
- OAuth 2.0 访问令牌。
- Client ID 和 Client Secret。
- 验证或重新配置你的 webhook:
- 使用你现有的 webhook URL,或设置一个新的(例如,https://your_domain.com/webhook/twitter)。
- 按照 V2 Webhooks API 文档 注册并管理你的 webhook。
- 示例应用:
- Simple webhook server
- 一个单文件的 Python 脚本,演示如何响应 CRC 检查并接收 POST 事件。
- Account Activity API sample dashboard
- 使用 bun.sh 编写的 Web 应用,便于你在应用内直接管理 webhooks、订阅并接收实时事件。
- Simple webhook server