本文整理汇总了Python中profiles.models.Profile.create_or_get_user方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.create_or_get_user方法的具体用法?Python Profile.create_or_get_user怎么用?Python Profile.create_or_get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类profiles.models.Profile
的用法示例。
在下文中一共展示了Profile.create_or_get_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: weibo_callback
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import create_or_get_user [as 别名]
def weibo_callback(request):
code = request.GET.get('code')
client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
r = client.request_access_token(code=code)
access_token = r.access_token
expires_in = r.expires_in
client.set_access_token(access_token, expires_in)
user_data = client.get.users__show(uid=r.uid, access_token=access_token)
username = user_data['name']
user_id = user_data['id']
description = user_data['description']
avatar_large = user_data['avatar_large']
user_timeline = client.get.statuses__user_timeline(access_token=access_token, uid=r.uid)
weibo_history = [d['text'] for d in user_timeline['statuses']]
user = Profile.create_or_get_user(username=username, password='', access_token=access_token, centroid=[10, 10],
sns_id=user_id, description=description, avatar=avatar_large, expires_in=expires_in,
weibo_history=weibo_history)
return HttpResponse(to_json(username=user.username, user_id=user.sns_id,
description=user.description, avatar_large=user.avatar))