Django:Facebook Connect Oauth2 权限
在我的 Django 项目中,我设置了 pyfacebook & django-facebookconnect 让用户使用其 Facebook 帐户登录。不过,我现在需要获得正确的权限来获取用户的数据和权限。将其保存在我的数据库中。
如何为 pyfacebook 和 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
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.
How do you add the permissions to pyfacebook & django-facebookconnect?
In facebook.init.py there is this function which I think is where I need to change the scope somehow.
Thanks for the help!
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:
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 calls:
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.debug.js" type="text/javascript">
</script
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终,我切换到了 django socialregistration 模块 &效果很好。
Ultimately, I switched over to the django socialregistration module & that worked great.