Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #532 #533

Merged
merged 2 commits into from Mar 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 25 additions & 3 deletions social/backends/weibo.py
Expand Up @@ -14,6 +14,7 @@ class WeiboOAuth2(BaseOAuth2):
AUTHORIZATION_URL = 'https://api.weibo.com/oauth2/authorize'
REQUEST_TOKEN_URL = 'https://api.weibo.com/oauth2/request_token'
ACCESS_TOKEN_URL = 'https://api.weibo.com/oauth2/access_token'
ACCESS_TOKEN_INFO_URL = 'https://api.weibo.com/oauth2/get_token_info'
ACCESS_TOKEN_METHOD = 'POST'
REDIRECT_STATE = False
EXTRA_DATA = [
Expand All @@ -39,7 +40,28 @@ def get_user_details(self, response):
'first_name': first_name,
'last_name': last_name}

def get_uid(self, access_token):
""" return uid by access_token"""

response = self.request(self.ACCESS_TOKEN_INFO_URL,
method='POST',
params={'access_token':access_token})

data = response.json()
return data['uid']

def user_data(self, access_token, *args, **kwargs):
return self.get_json('https://api.weibo.com/2/users/show.json',
params={'access_token': access_token,
'uid': kwargs['response']['uid']})
""" if use access_token for ajax auth, then would raise KeyError
because there is no uid in response, so must get uid.
"""
if 'response' not in kwargs or 'uid' not in kwargs['response']:
uid = self.get_uid(access_token)
response = kwargs.setdefault('response', {})
response['uid'] = uid

response = self.get_json('https://api.weibo.com/2/users/show.json',
params={'access_token': access_token,
'uid': kwargs['response']['uid']})

response['uid'] = kwargs['response']['uid']
return response