Repository: pennersr/django-allauth

Issue:
Feature Request: Configurable support for Twitter include_email=true
At the moment Twitter doesn't provide e-mail addresses with extra_data by default, but instead they have started allowing dev's to get apps whitelisted (after linking a ToS and Privacy notice). When the app is whitelisted you're able to get the user's e-mail address by appending include_email=true to the verify_credentials.json query.

In my case I've modified the Twitter provider view to add this tag line, although it would be much more convenient if this was a configurable option through the Twitter provider.



Discussion:
There is a setting `SOCIALACCOUNT_QUERY_EMAIL`, depending on which the `include_email` parameter should be inserted. Looking forward to a pull request :)

Ha :) I'll work on it as soon as I get this app out the door. First I need to figure out how to successfully overriding the signup forms with a UserProfile.

Does it make sense to just vary it based on SOCIALACCOUNT_QUERY_EMAIL when the user also needs to go through a process with Twitter? I'm still having some trouble getting it into my signup form, but it should flow through.

If including the `include_email` parameter does not have any negative impact when you run it with an unverified app (other than ofcourse not getting the actual email address), then just hook it up to the existing setting.

It seems to be okay with or without permission from Twitter. I'm just trying to sort out how to get the initial e-mail value passed along to the form - I've got it saving via a signal in the back end now, but it doesn't show up for the user.

See the `TwitterProvider` class. You will need to update the `extract_common_fields` method, so that it exposes `email` . If you have additional information, such as verified Y/N or primary Y/N, then add a `extract_email_addresses` method. See the FB provider for an example.


Resolving patch:
diff --git a/allauth/socialaccount/providers/twitter/provider.py b/allauth/socialaccount/providers/twitter/provider.py
--- a/allauth/socialaccount/providers/twitter/provider.py
+++ b/allauth/socialaccount/providers/twitter/provider.py
@@ -46,7 +46,8 @@ def extract_uid(self, data):
 
     def extract_common_fields(self, data):
         return dict(username=data.get('screen_name'),
-                    name=data.get('name'))
+                    name=data.get('name'),
+                    email=data.get('email'),)
 
 
 providers.registry.register(TwitterProvider)
diff --git a/allauth/socialaccount/providers/twitter/views.py b/allauth/socialaccount/providers/twitter/views.py
--- a/allauth/socialaccount/providers/twitter/views.py
+++ b/allauth/socialaccount/providers/twitter/views.py
@@ -1,5 +1,6 @@
 import json
 
+from allauth.socialaccount.app_settings import QUERY_EMAIL
 from allauth.socialaccount.providers.oauth.client import OAuth
 from allauth.socialaccount.providers.oauth.views import (OAuthAdapter,
                                                          OAuthLoginView,
@@ -12,7 +13,8 @@ class TwitterAPI(OAuth):
     """
     Verifying twitter credentials
     """
-    url = 'https://api.twitter.com/1.1/account/verify_credentials.json'
+    _base_url = 'https://api.twitter.com/1.1/account/verify_credentials.json'
+    url = _base_url + '?include_email=true' if QUERY_EMAIL else _base_url
 
     def get_user_info(self):
         user = json.loads(self.query(self.url))


Test patch: