1. Set up your Twitter app¶
- Create an app at apps.twitter.com. If you are creating the app on behalf of your company, it is recommended you create the app with a corporate Twitter account.
- Enable “Read, Write and Access direct messages” on the permissions tab of your app page.
- Generate access tokens for the app owner at the bottom of the “Keys and Access Tokens” tab. On this same tab take note of your Consumer Key, Consumer Secret, Access Token and Access Token secret. You will need these to use the API.
- If you are unfamiliar with Twitter Sign-in and how user contexts work with the Twitter API review Obtaining Access Tokens.
2. Webhook setup¶
- Review Securing Webhooks documention taking special note of the Challenge Response Check (CRC) requirements.
- Create a web app with an endpoint to use as your webhook to receive events (e.g. https://mydomain.com/webhook/twitter).
- Make sure your webhook supports POST requests for incoming events and GET requests for the CRC.
- Register your webhook URL with your app using POST account_activity/webhooks.
- Use the returned
webhook_idto add user subscriptions with POST account_activity/webhooks/:webhook_id/subscriptions.
3. Validate setup¶
- To validate your app and webhook are configured correctly, send a DM to one of the @usernames your app is subscribed to. You should recieve a DM event via a POST request to your webhook for each DM received.