1

在我的 Django 项目中,我设置了pyfacebookdjango-facebookconnect让用户使用他们的 Fb 帐户登录。但是,我现在需要获得正确的权限才能获取用户的数据并将其保存在我的数据库中。

如何将权限添加到 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 
4

1 回答 1

0

最终,我切换到了 django socialregistration模块,效果很好。

于 2011-02-21T05:37:12.367 回答