Django - 在facebook登录重定向后更改url

时间:2012-12-03 11:04:41

标签: facebook python-2.7 facebook-login django-1.4

我正在服务器端登录facebook,成功登录后,用户被重定向到正确的位置和所有内容,但网址末尾有许多特殊标志。

这是我的登录功能:

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/#_=_

什么可能导致网址改变?

0 个答案:

没有答案