<a id="x-formerly-twitter"></a>

# X (formerly Twitter)

<a id="backend-class"></a>

## Backend class

For Django, add this class path to `AUTHENTICATION_BACKENDS`. For other
integrations, use the same class path in the framework-specific backend
setting.

| Backend name   | Class path                                  |
|----------------|---------------------------------------------|
| `twitter`      | `social_core.backends.twitter.TwitterOAuth` |

Twitter offers per application keys named `Consumer Key` and `Consumer Secret`.
To enable Twitter these two keys are needed. Further documentation at
[Twitter development resources](https://dev.twitter.com/oauth):

- Register a new application at [Twitter App Creation](https://apps.twitter.com/apps/new),
- Check the **Allow this application to be used to Sign in with Twitter**
  checkbox. If you don’t check this box, Twitter will force your user to login
  every time.
- Fill **Consumer Key** and **Consumer Secret** values:
  ```default
  SOCIAL_AUTH_TWITTER_KEY = ''
  SOCIAL_AUTH_TWITTER_SECRET = ''
  ```
- You need to specify an URL callback or the OAuth will raise a “403 Client Error”.
  The callback URL should be something like “[https://example.com/complete/twitter](https://example.com/complete/twitter)”
- You can request user’s Email address (consult [Twitter verify
  credentials](https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-account-verify_credentials)), the parameter is sent automatically, but the
  application needs to be whitelisted in order to get a valid value.
- You’ll need to apply for Elevated access via the Developer Portal, see [Twitter access levels](https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-level) for more info.

Twitter usually fails with a 401 error when trying to call the request-token
URL, this is usually caused by server datetime errors (check miscellaneous
section). Installing `ntp` and syncing the server date with some pool does
the trick.
