我有一个问题,Facebook 帐户信息不是“用户”而是“NoneType”类型,因此在第一次 Facebook 社交身份验证后我无法将图像保存为扩展用户模型信息(用户配置文件)。
如果需要任何其他信息,请通知我。
设置.py:
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
'fields': 'id,name,email',
}
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
'ridemaker.pipeline.save_profile',
)
管道.py:
from accounts.models import UserProfile
from social_core.backends.facebook import FacebookOAuth2, FacebookAppOAuth2
from urllib.request import urlopen
from django.template.defaultfilters import slugify
from django.core.files.base import ContentFile
def save_profile(backend, details, response, uid,\
user, *args, **kwargs):
if backend.__class__ == FacebookOAuth2:
url = "http://graph.facebook.com/%s/picture?type=large" % response['id']
avatar = urlopen(url)
#Why is user argument "None"?
profile = user.userprofile
profile.image.save(slugify(user.username + " social") + '.jpg',
ContentFile(avatar.read()))
profile.save()
最佳答案
您正在覆盖设置中的 SOCIAL_AUTH_PIPELINE
,并且错过了创建用户的管道 social_core.pipeline.user.create_user
。在 SOCIAL_AUTH_PIPELINE
中的 social_core.pipeline.social_auth.social_user
之后放置两个管道:
'social_core.pipeline.user.get_username',
'social_core.pipeline.user.create_user',
关于python - AttributeError at/account/login/oauth/complete/facebook/'NoneType' 对象没有属性 'userprofile',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43893604/