Django:Facebook Connect Oauth2权限 [英] Django: Facebook Connect Oauth2 Permissions

查看:152
本文介绍了Django:Facebook Connect Oauth2权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Django项目中,我已经设置了 pyfacebook & django-facebookconnect 让用户使用他们的Fb帐号登录。不过,我现在需要获得正确的权限,以获得用户的数据和保存在我的数据库中。

In my Django project, I have set up pyfacebook & django-facebookconnect to let the user login with their Fb account. However I now need to get the right permissions to get the user's data & save it in my db.

如何将权限添加到pyfacebook& django-facebookconnect?

在Facebook中。 init .py有这个功能,我认为是我需要更改

In facebook.init.py there is this function which I think is where I need to change the scope somehow.

感谢您的帮助。

   def get_login_url(self, next=None, popup=False, canvas=True,
                      required_permissions=None):
        """
        Returns the URL that the user should be redirected to in order to login.

        next -- the URL that Facebook should redirect to after login
        required_permissions -- permission required by the application

        """
        if self.oauth2:
            args = {
                'client_id': self.app_id,
                'redirect_uri': next,
            }

            if required_permissions:
                args['scope'] = required_permissions

            if popup:
                args['display'] = 'popup'

            return self.get_graph_url('oauth/authorize', **args)
        else:
            args = {'api_key': self.api_key, 'v': '1.0'}

            if next is not None:
                args['next'] = next

            if canvas is True:
                args['canvas'] = 1

            if popup is True:
                args['popup'] = 1

            if required_permissions:
                args['req_perms'] = ",".join(required_permissions)

            if self.auth_token is not None:
                args['auth_token'] = self.auth_token

            return self.get_url('login', **args)






更新:


Update:

当您点击连接按钮时,它通过facebookConnect:

When you click the connect button, it passes facebookConnect:

<script type="text/javascript">
    FB_RequireFeatures(["XFBML"], function() {FB.Facebook.init("{{ facebook_api_key }}", "{% url facebook_xd_receiver %}")});

    function facebookConnect(loginForm) {
        FB.Connect.requireSession();
        FB.Facebook.get_sessionState().waitUntilReady(function(){loginForm.submit();});
    }
    function pushToFacebookFeed(data){
        if(data['success']){
            var template_data = data['template_data'];
            var template_bundle_id = data['template_bundle_id'];
            feedTheFacebook(template_data,template_bundle_id,function(){});
        } else {
            alert(data['errors']);
        }
    }
    function pushToFacebookFeedAndRedirect(data){
        if(data['success']){
            var template_data = data['template_data'];
            var template_bundle_id = data['template_bundle_id'];
            feedTheFacebook(template_data,template_bundle_id,function(){window.location.href=template_data['url'];});
        } else {
            alert(data['errors']);
        }
    }
    function pushToFacebookFeedAndReload(data){
        if(data['success']){
            var template_data = data['template_data'];
            var template_bundle_id = data['template_bundle_id'];
            feedTheFacebook(template_data,template_bundle_id,function(){window.location.reload();});
        } else {
            alert(data['errors']);
        }
    }
    function feedTheFacebook(template_data,template_bundle_id,callback) {
        FB.Connect.showFeedDialog(
            template_bundle_id,
            template_data,
            null, null, null,
            FB.RequireConnect.promptConnect,
            callback
        );
    }
</script>

xd_receiver电话:

xd_receiver calls:

 <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.debug.js" type="text/javascript">
</script 


推荐答案

最终,切换到django socialregistration 模块&这很棒。

Ultimately, I switched over to the django socialregistration module & that worked great.

这篇关于Django:Facebook Connect Oauth2权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆