Django:Facebook Connect Oauth2权限

时间:2011-02-19 19:41:24

标签: python django facebook facebook-graph-api oauth-2.0

在我的Django项目中,我设置了pyfacebook& django-facebookconnect让用户使用自己的Fb帐户登录。但是我现在需要获得正确的permissions来获取用户的数据&把它保存在我的数据库中。

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

在facebook。 init .py中有这个函数,我认为我需要以某种方式更改范围。

感谢您的帮助!

   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)

更新

单击连接按钮时,它会通过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调用:

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

1 个答案:

答案 0 :(得分:0)

最终,我切换到django socialregistration模块&amp;这很有效。