本文整理汇总了Python中social.apps.django_app.default.models.UserSocialAuth.get_social_auth_for_user方法的典型用法代码示例。如果您正苦于以下问题:Python UserSocialAuth.get_social_auth_for_user方法的具体用法?Python UserSocialAuth.get_social_auth_for_user怎么用?Python UserSocialAuth.get_social_auth_for_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类social.apps.django_app.default.models.UserSocialAuth
的用法示例。
在下文中一共展示了UserSocialAuth.get_social_auth_for_user方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_sheet_with_user
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def download_sheet_with_user(user, filename="membership.csv"):
"""
Download the membership with a user's credentials
:type user: users.models.User
:param user:
:return: boolean of successful download
"""
try:
social = UserSocialAuth.get_social_auth_for_user(user).get()
except UserSocialAuth.DoesNotExist:
return False
extra = social.extra_data
expiry = datetime.utcnow() + timedelta(seconds=int(extra["expires"]))
credentials = OAuth2Credentials(
extra["access_token"],
settings.SOCIAL_AUTH_GOOGLE_OAUTH2_KEY,
settings.SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET,
extra["refresh_token"],
expiry,
GOOGLE_TOKEN_URI,
None,
revoke_uri=GOOGLE_REVOKE_URI,
)
service = build_service_from_credentials(credentials)
try:
file = service.files().get(fileId=settings.GOOGLE_MEMBERSHIP_FILE_ID).execute()
except googleapiclient.errors.HttpError:
return False
url = file["exportLinks"]["text/csv"]
resp, content = service._http.request(url)
open(filename, "wb").write(content)
return True
示例2: __init__
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def __init__(self, user, request=None, provider='google-oauth2'):
self.user = user
self.request = request
self.provider = provider
self.strategy = load_strategy(request)
self.user_social = UserSocialAuth.get_social_auth_for_user(user=self.user, provider=self.provider)[0]
self.backend = self.user_social.get_backend_instance(strategy=self.strategy)
示例3: profile_image_for_user
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def profile_image_for_user(user):
try:
auth = UserSocialAuth.get_social_auth_for_user(user)[0]
backend = auth.get_backend().name
if backend == "google-oauth2":
return HttpResponseRedirect(auth.extra_data["image"]["url"])
elif backend == "facebook":
return HttpResponseRedirect(fb_profile_image(auth.uid,50,50))
except Exception, e:
pass
示例4: get_large_user_image
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def get_large_user_image(user):
try:
auth = UserSocialAuth.get_social_auth_for_user(user)[0]
backend = auth.get_backend().name
if backend == "google-oauth2":
url = auth.extra_data["image"]["url"]
return HttpResponseRedirect("%s%i" % (url[:-2],200))
elif backend == "facebook":
return HttpResponseRedirect(fb_profile_image(auth.uid,200,200))
except Exception, e:
pass