# How do I retrieve the email from an X (Twitter) social login?

**URL:** <https://community.auth0.com/t/how-do-i-retrieve-the-email-from-an-x-twitter-social-login/156912>\
**Category:** Get Help\
**Tags:** identifier-first, login-experience\
**Created:** [December 3, 2024, 1:18pm UTC](https://community.auth0.com/t/how-do-i-retrieve-the-email-from-an-x-twitter-social-login/156912 "2024-12-03T13:18:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![prioste92](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/prioste92/32/64678_2.png) [@prioste92](https://community.auth0.com/u/prioste92)\
**Post date:** [December 3, 2024, 1:18pm UTC](https://community.auth0.com/t/how-do-i-retrieve-the-email-from-an-x-twitter-social-login/156912/1 "2024-12-03T13:18:42Z")

</div>

Hi everyone,  
I’m trying to retrieve the email from an X (Twitter) social login. I followed [this guide](https://marketplace.auth0.com/integrations/twitter-social-connection) to set up the X flow. However, I couldn’t find the ‘Get Email Address from Twitter’ template under the ‘Enrich Profile’ section.

I’m unsure how to configure Auth0 to get the email from X (Twitter). Can you help me with this?

---

<div class="post-metadata">

**Author:** ![valerian](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/valerian/32/62115_2.png) [@valerian](https://community.auth0.com/u/valerian)\
**Post date:** [December 4, 2024, 9:37am UTC](https://community.auth0.com/t/how-do-i-retrieve-the-email-from-an-x-twitter-social-login/156912/4 "2024-12-04T09:37:32Z")

</div>

Hi @prioste92,

Welcome to the Auth0 Community! I’d recommend checking the following article: [X (formerly Twitter) Social Connection Cannot Fetch the Email Attribute when Migrating from Rules to Actions](https://community.auth0.com/t/x-formerly-twitter-social-connection-cannot-fetch-the-email-attribute-when-migrating-from-rules-to-actions/146257)

Thanks!  
Valerian

---

<div class="post-metadata">

**Author:** ![prioste92](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/prioste92/32/64678_2.png) [@prioste92](https://community.auth0.com/u/prioste92)\
**Post date:** [December 4, 2024, 11:59am UTC](https://community.auth0.com/t/how-do-i-retrieve-the-email-from-an-x-twitter-social-login/156912/5 "2024-12-04T11:59:28Z")

</div>

I saw that post, but it’s not clear how to retrieve the email from Twitter. Could you provide an example or point me to documentation that explains how to implement this?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [December 18, 2024, 12:12am UTC](https://community.auth0.com/t/how-do-i-retrieve-the-email-from-an-x-twitter-social-login/156912/8 "2024-12-18T00:12:02Z")

</div>

Hi @prioste92,

To get the email from Twitter, here is the **Get Email Address from Twitter** Rule that needs to be converted to a Post Login Action:

```auto
function getTwitterEmail(user, context, callback) {
  // additional request below is specific to Twitter
  if (context.connectionStrategy !== 'twitter') {
    return callback(null, user, context);
  }

  const _ = require('lodash');
  const request = require('request');
  const oauth = require('oauth-sign');
  const uuid = require('uuid');

  const url = 'https://api.twitter.com/1.1/account/verify_credentials.json';
  const consumerKey = configuration.TWITTER_CONSUMER_KEY;
  const consumerSecretKey = configuration.TWITTER_CONSUMER_SECRET_KEY;

  const twitterIdentity = _.find(user.identities, { connection: 'twitter' });
  const oauthToken = twitterIdentity.access_token;
  const oauthTokenSecret = twitterIdentity.access_token_secret;

  const timestamp = Date.now() / 1000;
  const nonce = uuid.v4().replace(/-/g, '');

  const params = {
    include_email: true,
    oauth_consumer_key: consumerKey,
    oauth_nonce: nonce,
    oauth_signature_method: 'HMAC-SHA1',
    oauth_timestamp: timestamp,
    oauth_token: oauthToken,
    oauth_version: '1.0'
  };

  params.oauth_signature = oauth.hmacsign(
    'GET',
    url,
    params,
    consumerSecretKey,
    oauthTokenSecret
  );

  const auth = Object.keys(params)
    .sort()
    .map(function (k) {
      return k + '="' + oauth.rfc3986(params[k]) + '"';
    })
    .join(', ');

  request.get(
    url + '?include_email=true',
    {
      headers: {
        Authorization: 'OAuth ' + auth
      },
      json: true
    },
    (err, resp, body) => {
      if (resp.statusCode !== 200) {
        return callback(
          new Error('Error retrieving email from twitter: ' + body || err)
        );
      }
      user.email = body.email;
      return callback(err, user, context);
    }
  );
}

```

During your conversion, you will need to ensure you use the Management API to get the user’s identities array to obtain the Identity Provider’s access\_token and access\_token\_secret information as mentioned in [this knowledge article](https://community.auth0.com/t/x-formerly-twitter-social-connection-cannot-fetch-the-email-attribute-when-migrating-from-rules-to-actions/146257).

Please also refer to our [Using the Management API in Actions](https://community.auth0.com/t/using-the-management-api-in-actions/64947) knowledge article.

And here is another useful resource to help you: [Migrate from Rules to Actions](https://auth0.com/docs/customize/actions/migrate/migrate-from-rules-to-actions)

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 1, 2025, 12:12am UTC](https://community.auth0.com/t/how-do-i-retrieve-the-email-from-an-x-twitter-social-login/156912/9 "2025-01-01T00:12:23Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
