Search code examples
phpandroidtwittertwitter-oauth

Using Twitter OAuth Echo for verify_credential, how can I get email?


I have mobile app, and I need to registrate user with twitter.

I'm getting params X-Auth-Service-Provider and X-Verify-Credentials-Authorization for OAuth Echo and send them to server

Server calls verify_credentials and gets Twitter User Profile.

But this profile does not contain user's email, how can I get user's email at backend, while authorizing user in mobile app?


Solution

  • To request a user’s email address, your application needs to be whitelisted by Twitter. To do that, you need:

    1. Fill the following form on the Twitter API Policy Support.
    2. Select the I need access to special permissions option.
    3. You'll need to fill your application name and ID (you can fetch these from https://apps.twitter.com).
    4. In the permission list, select the permissions you need. In your case, it should be Email address.
    5. Submit

    Once your request is approved or if you're already whitelisted, you can go back to https://apps.twitter.com and under the app permissions section, a new checkbox Request email addresses from users will be available. You'll need to enable this new option. The Privacy Policy URL and Terms of Service URL fields will also be available.

    At this point, you can add the include_email parameter to your account/verify_credentials request.

    Some related points:

    • Users will be informed that your app is requesting the email address during the login process.
    • You'll only get verified email addresses, if the user did not provide any email address or did not verify it, you'll get null.
    • If you already have authenticated users, you'll need to regenerate the user access token to get the email address.