Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
use 'oauth2' google service instead of 'plus' service
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyclark committed Jun 5, 2013
1 parent 1306793 commit 4382dca
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions flask_social/providers/google.py
Expand Up @@ -30,20 +30,24 @@
},
'request_token_params': {
'response_type': 'code',
'scope': 'https://www.googleapis.com/auth/plus.me'
'scope': 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me'
#add ' https://www.googleapis.com/auth/userinfo.email' to scope to also get email
}
}

def _get_api(credentials):
http = httplib2.Http()
http = credentials.authorize(http)
api = googleapi.build('oauth2', 'v2', http=http)
return api


def get_api(connection, **kwargs):
credentials = googleoauth.AccessTokenCredentials(
access_token=getattr(connection, 'access_token'),
user_agent=''
)

http = httplib2.Http()
http = credentials.authorize(http)
return googleapi.build('plus', 'v1', http=http)
return _get_api(credentials)


def get_provider_user_id(response, **kwargs):
Expand All @@ -52,11 +56,7 @@ def get_provider_user_id(response, **kwargs):
access_token=response['access_token'],
user_agent=''
)

http = httplib2.Http()
http = credentials.authorize(http)
api = googleapi.build('plus', 'v1', http=http)
profile = api.people().get(userId='me').execute()
profile = _get_api(credentials).userinfo().get().execute()
return profile['id']
return None

Expand All @@ -72,17 +72,13 @@ def get_connection_values(response, **kwargs):
user_agent=''
)

http = httplib2.Http()
http = credentials.authorize(http)
api = googleapi.build('plus', 'v1', http=http)
profile = api.people().get(userId='me').execute()

profile = _get_api(credentials).userinfo().get().execute()
return dict(
provider_id=config['id'],
provider_user_id=profile['id'],
access_token=access_token,
secret=None,
display_name=profile['displayName'],
profile_url=profile['url'],
image_url=profile['image']['url']
)
display_name=profile['name'],
profile_url=profile.get('link'),
image_url=profile.get('picture')
)

0 comments on commit 4382dca

Please sign in to comment.