|
|
|
้html5 javascript ล็อกอินด้วยFacebook อยากให้ข้อมูลfacebookไปแสดงหน้าอื่นด้วย |
|
|
|
|
|
|
|
้html5 javascript ล็อกอินเข้าเว็บด้วย Facebook อยากนำเอาข้อมูล facebook ที่ได้จากการล็อกอินไปแสดงหน้าอื่นด้วย แต่โค๊ดตอนนี้มันแสดงหน้าเดิม ล็อกอินเสร็จปุ่มจะหายแล้วข้อมูลจะแสดงแทน
Code
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>LOG IN</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet prefetch' href='http://fonts.googleapis.com/css?family=Raleway'>
<link rel='stylesheet prefetch' href='http://weloveiconfonts.com/api/?family=fontawesome'>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<br>
<br>
<br>
<br>
<form action="#" id="login-form">
<div class="heading">Login to Application</div>
<center><div class="right">
<br>
<div class="connect">Connect with</div>
<div id="fb-root"></div>
<script src="js/facebook.js"></script>
<div align="center">
<br>
<br>
<div id="status">
<br>
<img src="http://hayageek.com/examples/oauth/facebook/oauth-javascript/LoginWithFacebook.png" style="cursor:pointer;" onClick="Login()"/>
</div>
<br/><br/><br/><br/><br/>
</div>
</div></center>
<br>
</form>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'app id', // App ID
channelUrl : 'http://saladlovers.net', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function(response)
{
if (response.status === 'connected')
{
document.getElementById("message").innerHTML += "<br>Connected to Facebook";
//SUCCESS
}
else if (response.status === 'not_authorized')
{
document.getElementById("message").innerHTML += "<br>Failed to Connect";
//FAILED
} else
{
document.getElementById("message").innerHTML += "<br>Logged Out";
//UNKNOWN ERROR
}
});
};
function Login()
{
FB.login(function(response) {
if (response.authResponse)
{
getPhoto();
getUserInfo();
} else
{
console.log('User cancelled login or did not fully authorize.');
}
},{scope: 'email,user_photos,user_videos'});
}
function getPhoto() {
FB.api('/me/picture?type=normal', function(response) {
var str="<br><center><img src='"+response.data.url+"'/><br></center>";
document.getElementById("status").innerHTML+=str;
});
}
function getUserInfo() {
FB.api('/me?fields=id,name,email', function(response) {
var str="สวัสดีคุณ "+response.name+"<br><br>";
str +="<b>Member Infprmation </b><br><br>";
str +="Facebook Name: "+response.name+"<br>";
str +="id: "+response.id+"<br>";
str +="Email: "+response.email+"<br><br>";
str +="<input type='button' value='Logout' onclick='Logout();'/><br><br";
document.getElementById("status").innerHTML=str;
});
}
function getShowUser() {
getPhoto();
getUserInfo();
}
function Logout()
{
FB.logout(function(){document.location.reload();});
}
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
</body>
</html>
Tag : HTML/CSS, Ajax, jQuery, WebService, Web Service
|
|
|
|
|
|
Date :
2016-12-08 13:45:52 |
By :
aummyasia |
View :
1403 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จะต้องใช้เก็บลงพวก Session ก้ได้ครับ
|
|
|
|
|
Date :
2016-12-09 15:46:02 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|