身份验证后使用Javascript SDK重定向URI
Redirect URI using the Javascript SDK after authentication
所以我已经在我的网站主页上设置了一个基本的登录/认证流程。在身份验证对话框之后,我想将它们重定向到我网站上的另一个页面。我已经尝试了现有代码的几种变体,在开发人员应用程序的基本设置下更改了网站url,尝试了不同的oauth流,但是,它仍然只是重定向到他们登录的同一个主页。我知道这听起来非常简单,但是有太多不同的身份验证流和实现,这有点令人困惑。
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXXX', // App ID
channelURL : '//localhost/dataweavr/channel.php', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
// Additional initialization code here
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
还有更多的乐趣…
<div id="fb-root"></div>
<div id="user-info"></div>
<button id="fb-auth">Login</button>
<script>
window.fbAsyncInit = function() {
FB.init({ appId: 'XXXXXXXXXXXXXXXXXXXXXX',
status: true,
cookie: true,
xfbml: true,
oauth: true});
function updateButton(response) {
var button = document.getElementById('fb-auth');
if (response.authResponse) {
//user is already logged in and connected
var userInfo = document.getElementById('user-info');
FB.api('/me', function(response) {
userInfo.innerHTML = '<img src="https://graph.facebook.com/'
+ response.id + '/picture">' + response.name;
button.innerHTML = 'Logout';
});
button.onclick = function() {
FB.logout(function(response) {
var userInfo = document.getElementById('user-info');
userInfo.innerHTML="";
});
};
} else {
//user is not connected to your app or logged out
button.innerHTML = 'Login';
button.onclick = function() {
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
var userInfo = document.getElementById('user-info');
userInfo.innerHTML =
'<img src="https://graph.facebook.com/'
+ response.id + '/picture" style="margin-right:5px"/>'
+ response.name;
});
} else {
//user cancelled login or did not grant authorization
}
}, {scope:'email,user_birthday'});
}
}
}
// run once with current status and whenever the status changes
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol
+ '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
还有一个不相关的问题。为什么我只有一个正常的按钮弹出?如何让SDK渲染Facebook登录按钮,而不仅仅是一个简单的登录按钮?
您应该能够在登录响应后重定向用户。以下几行:
FB.login(function(response) {
if (response.authResponse) {
添加如下内容:
window.top.location = "http://page_to_redirect";
按钮的东西,嗯…好吧,你在html中写一个简单的登录按钮,如果你想要一个登录按钮,改变这个:登录
:
<fb:login-button></fb:login-button>
希望能有所帮助。
相关文章:
- 通过javascript重定向html传递php变量
- JavaScript下拉菜单-点击按钮并根据所选值重定向到url
- 使用angular重定向到html页面
- 如何在chrome扩展中重定向到html页面
- 无法从jquery Mobile导航栏重定向到另一个页面
- ng视图外的链接重定向到ng视图内的页面
- 在phonegap应用程序内部重定向不起作用
- CORS-重定向到第二个GET正在接收的页面
- AJAX不会在文件上传后重定向到网页-POST方法
- 重定向时角度刷新浏览器
- 通过链接重定向不;我不在jstree中工作
- 根据select选项元素将表单重定向到不同的URL
- 通过JQuery重定向到另一个页面
- 重定向到“父窗口”
- 重定向iFrame中的父URL
- 从URL获取数据并阻止自动重定向(插件SDK Mozilla)
- Facebook SDK和OAuth 2.0 -在JavaScript和重定向中使用令牌
- 从SDK重定向S3桶
- Facebook javascript sdk fb.登录不重定向
- 身份验证后使用Javascript SDK重定向URI