我正在对 facebook 进行服务器端登录,成功登录后,用户被重定向到正确的位置和所有内容,但 url 最后有许多特殊标志。
这是我的登录功能:
def fb_login(request):
args = dict(client_id=FACEBOOK_APP_ID, redirect_uri=request.build_absolute_uri())
# the user is already logged into facebook
if 'code' in request.GET:
args['client_secret'] = FACEBOOK_APP_SECRET
args['code'] = request.GET.get('code')
response = urlparse.parse_qs(urllib.urlopen("https://graph.facebook"
".com/oauth/access_token?" +
urllib.urlencode(args)).read())
# A short lived access token
access_token = response['access_token'][0]
# Extending the short lived access token
args['grant_type'] = "fb_exchange_token"
args['fb_exchange_token'] = access_token
reponse2 = urlparse.parse_qs(urllib.urlopen("https://graph.facebook"
".com/oauth/access_token?" +
urllib.urlencode(args)).read())
token = Token.objects.create(token=reponse2['access_token'][0],
expires_in=int(reponse2['expires'][0]))
# do stuff with the token
return HttpResponseRedirect(reverse('profile'))
# the user is not logged into facebook yet
else:
return HttpResponseRedirect("https://graph.facebook.com/oauth/authorize?" +
urllib.urlencode(args))
而不是这个网址:
http://localhost:8000/profile/
我明白了:
http://localhost:8000/profile/#_=_
什么会导致 url 像这样改变?