gpt4 book ai didi

python - django 获取社会 token 形式 allauth

转载 作者:太空宇宙 更新时间:2023-11-03 13:15:43 29 4
gpt4 key购买 nike

您好,我试图从数据库中获取社交 token ,但出现此错误。我找不到任何答案并尝试了我能想到的一切。

如果有人知道如何解决这个问题,请。

NameError at /
name 'user' is not defined
Request Method: GET
Request URL: http://localhost:3000/
Django Version: 1.8.2
Exception Type: NameError
Exception Value:
name 'user' is not defined
Exception Location: /home/dk/user-new/just/fb/views.py in home, line 14
Python Executable: /home/dk/user-new/bin/python
Python Version: 3.4.0
Python Path:
['/home/dk/user-new/just',
'/home/dk/user-new/lib/python3.4',
'/home/dk/user-new/lib/python3.4/plat-x86_64-linux-gnu',
'/home/dk/user-new/lib/python3.4/lib-dynload',
'/usr/lib/python3.4',
'/usr/lib/python3.4/plat-x86_64-linux-gnu',
'/home/dk/user-new/lib/python3.4/site-packages']
Server time: Wed, 17 Jun 2015 10:09:50 +0000






from django.shortcuts import render
import requests
from allauth.socialaccount import providers
from allauth.socialaccount.models import SocialLogin, SocialToken, SocialApp
from allauth.socialaccount.providers.facebook.views import fb_complete_login
from allauth.socialaccount.helpers import complete_social_login
import allauth.account


def home(request):

access_token = SocialToken.objects.filter(user=user, account__provider='facebook')

更新:

我添加了指向 allauth 包模型的链接。

新的错误是:

AttributeError 在/类型对象“SocialLogin”没有属性“帐户”

def home(request):
#user = request.user

user = SocialLogin.account.user
access_token = SocialToken.objects.filter(account=user,account__provider='facebook')

https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/models.py

更新:

无法将“QuerySet”对象隐式转换为 str

access_token = SocialToken.objects.filter(account__user=request.user, account__provider='facebook') 
r = requests.get('https://graph.facebook.com/me?access_token='+access_token+'&fields=id,name,email') #MY_CORRECT_TOKEN&fields=id,name,email

最佳答案

你在使用它之前没有定义user变量

def home(request):
#user = request.user
access_token = SocialToken.objects.get(account__user=request.user, account__provider='facebook') #get instead of filter (you need only one object)

r = requests.get('https://graph.facebook.com/me?access_token='+access_token.token+'&fields=id,name,email') #add access_token.token to your request

关于python - django 获取社会 token 形式 allauth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30888487/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com