GithubHelp home page GithubHelp logo

Comments (9)

omab avatar omab commented on September 26, 2024

Hi,

I think there's not service google service to get such information. Let me know if you find anything.

Thanks

from django-social-auth.

kevinpostal avatar kevinpostal commented on September 26, 2024

I found a way https://www-opensocial.googleusercontent.com/api/people

Here is an example:

token = 'O AUTH TOKEN'
scope = "https://www-opensocial.googleusercontent.com/api/people"
url = "%s/@me/@self" % scope
params='OAuth %s' % token 

request = Request(url, headers={'Authorization': params})
data =  simplejson.loads(urlopen(request).read())['entry']

first_name = data['name']['givenName']
last_name = data['name']['familyName']

I use this with Celery to download info plus avatar.

from django-social-auth.

omab avatar omab commented on September 26, 2024

Interesting, I'll take a look and add this to google auth methods.

Thanks!

from django-social-auth.

bashmish avatar bashmish commented on September 26, 2024

I want to implement this feature, but can't find any documentation about this API on Google Code.
Could anybody point me at it?

from django-social-auth.

omab avatar omab commented on September 26, 2024

I've tried working with that one too without luck :-/

from django-social-auth.

bashmish avatar bashmish commented on September 26, 2024

According to this discussion on Google Groups, Googlers are still working to implement appropriate API. Hope they do that at last.

from django-social-auth.

pshields avatar pshields commented on September 26, 2024

I think the scope should be https://www.googleapis.com/auth/userinfo.profile. Here is an example application with source.

from django-social-auth.

jsanchezpando avatar jsanchezpando commented on September 26, 2024

Just write this google oauth2 backend to get the full profile !

May be integrated in 'google-oauth2' backend ?

googlebackend.py:

from urllib import urlencode
from urllib2 import Request, urlopen

from django.utils import simplejson

from social_auth.backends import USERNAME
from social_auth.backends.google import GoogleOAuth2, GoogleOAuth2Backend, BACKENDS

import settings


class GoogleProfileBackend(GoogleOAuth2Backend):
    """Google OAuth2 authentication backend"""
    name = 'google-profile'

    def get_user_details(self, response):
        """Return user details from Google account"""
        email = response['email']
        return {USERNAME: email.split('@', 1)[0],
                'email': email,
                'fullname': response.get('name',''),
                'first_name': response.get('given_name',''),
                'last_name': response.get('family_name',''),
                'gender': response.get('gender','')}


class GoogleProfile(GoogleOAuth2):
    """Google OAuth2 support"""
    AUTH_BACKEND = GoogleProfileBackend

    def get_scope(self):
        return ['https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'] + \
               getattr(settings, 'GOOGLE_OAUTH_EXTRA_SCOPE', [])

    def user_data(self, access_token):
        """Return user data from Google API"""
        return self.googleapis_profile('https://www.googleapis.com/oauth2/v1/userinfo', access_token)

    def googleapis_profile(self, url, access_token):
        """Loads user data from googleapis service

        Google OAuth documentation at:
            http://code.google.com/apis/accounts/docs/OAuth2Login.html
        """
        data = {'access_token': access_token, 'alt': 'json'}
        request = Request(url + '?' + urlencode(data))
        try:
            return simplejson.loads(urlopen(request).read())
        except (ValueError, KeyError, IOError):
            return None

BACKENDS['google-profile'] = GoogleProfile

in settings.py:
add 'yourapp.googlebackend.GoogleProfileBackend' in the AUTHENTICATION_BACKENDS
and

SOCIAL_AUTH_IMPORT_BACKENDS = (
     'yourapp',
 )

expect was usfull...

from django-social-auth.

omab avatar omab commented on September 26, 2024

Issue fixed by pull request #284.

from django-social-auth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.