开始使用 Direct Message 管理类 endpoint
构建私信查找请求的步骤
第一步:从工具或库入手
步骤二:为请求进行身份验证
- 创建一个 Token Name,例如 “DM lookup.”
- 确认 Grant Type 设置为 Authorization Code (with PKCE)。
- 设置您的 Callback URL。需要将 Callback URL 更新为与 v2 Dev Portal 中与您的应用关联的 Callback URL 完全一致。本示例所用的 X App 的 Callback URL 设置为 - https://www.example.com.(注意必须完全匹配, https://example.com 将无法使用。)
- 确认 Auth URL 设置为 https://x.com/i/oauth2/authorize
- 确认 Access Token URL 设置为 https://api.x.com/2/oauth2/token.Client ID - 从开发者门户复制并粘贴 OAuth 2.0 Client ID Client Secret - 仅当您使用的是机密客户端类型的 App 时才需要。如果是,请从开发者门户复制并粘贴 OAuth 2.0 Client Secret。
- 确认 Scope 设置为 dm.read dm.write tweet.read users.read。
- 确认 State 设置为 “state.”
- 确认 Client Authentication 设置为 Send as Basic Auth header。
- 点击 “Get New Access Token”,在 “Sign-in with X” 流程中点击 “Authorize app”。
- 点击 “Proceed” 按钮,然后点击 “Use Token” 以生成令牌。
- 点击 “Save” 按钮保存这些配置信息。
步骤三:检索私信会话事件
Key | Value |
dm_conversation_id | 1228393702244134912 |
- 默认的 Direct Message 对象 fields:id、text 和 event_type。
- 额外的 Direct Message 对象 fields:dm_conversation_id、created_at、sender_id、attachments、participant_ids、referenced_tweets
Key | Value |
dm_event.fields | dm_conversation_id,created_at,sender_id,attachments,participant_ids,referenced_tweets |