我的用例:让用户从他的Android应用程序&获取访问令牌,然后将其传递给django。更具体地说,代码如下。 我使用django admin(即localhost / admin)
添加了我的应用程序的客户端ID和令牌我的代码
def facebook_login(request):
access_token = request.POST['access_token']
print(access_token)
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
try:
app = SocialApp.objects.get(provider="facebook")
print(app)
token = SocialToken(app=app,
token=access_token)
print(token)
login = fb_complete_login(app, token)
login.token = token
print(login)
login.state = SocialLogin.state_from_request(request)
ret = complete_social_login(request, login)
print(ret)
#if we get here we've succeeded
return HttpResponse("success")
except:
# FIXME: Catch only what is needed
return HttpResponse("failed")
如何在本地计算机上测试它是否有效?我需要什么设置?
否则
c=Client()
r=c.post('/login/',{'access_token':'adadasfvaera10238123094572zwcd'})
对于我从facebook获得的任何访问令牌,总是失败。我在哪里放入我的应用程序ID来启用它?