0
votes

I'm trying to get (and save) the user city or location using django and python-social-auth. It will be loaded on the first time the user logging, so I created a PIPELINE

  """
SOCIAL AUTH
"""
SOCIAL_AUTH_PIPELINE = (
    ...
    'libs.util.associate_by_email',
    'libs.util.load_data_new_user',
     ...
)
SOCIAL_AUTH_FACEBOOK_KEY = "...."
SOCIAL_AUTH_FACEBOOK_SECRET = "...."
SOCIAL_AUTH_FACEBOOK_SCOPE = [
    'email',
]

And the pipeline are looking like this:

def load_data_new_user(backend, response, user, *args, **kwargs):
print kwargs['details']
if user is None:
    if backend.name == "facebook":
        try:
            url = "http://graph.facebook.com/%s/picture?width=200&height=200&redirect=false" % response['id']
            data = json.loads(urllib2.urlopen(url).read())['data']
            print data
            return {'avatar': data}
        except StandardError:
            return {'avatar': None}
    else:
        raise ValueError()

It's working to get the avatar, but how can I catch the user city?

1

1 Answers

2
votes
  1. Add the user_location scope to the SOCIAL_AUTH_FACEBOOK_SCOPE setting
  2. Get the location by doing response['location'] in a pipeline (users that didn't fill their location in their profile won't have that key, so check for it first)