-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
84 lines (81 loc) · 3.12 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Jquery Facebook Login</title>
<script type="text/javascript">
/* Facebook Login */
(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));
// Additional JS functions here
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXXXXXXXXX', //Change the app id with your application app id
channelUrl : '', // Channel file for x-domain comms
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true,
xfbml : true, // parse XFBML
frictionlessRequests : true
});
};
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
/*
* Facebook login button Event
*/
$( document ).ready(function() {
$("#fb-login").click(function() {
FB.getLoginStatus(function(userloginstatus) {
console.log("FB.getLoginStatus Response");
console.log(userloginstatus);
if (userloginstatus.status === 'connected') {
FBfetchUserDetail(userloginstatus); // connected
}
else if (userloginstatus.status === 'not_authorized') {
FBUserlogin(); // not_authorized
}
else {
FBUserlogin(); // not_logged_in
}
});
});
});
function FBUserlogin()
{
FB.login(function(response) {
if (response.authResponse) {
// connected
console.log('User Already logged in');
console.log('login function connected response');
console.log(response);
FBfetchUserDetail(response);
} else {
// cancelled
console.log('login function cancelled response');
console.log(response);
}
}, {scope: 'email,publish_actions'});
}
function FBfetchUserDetail(userloginstatus)
{
FB.api('/me', function(userdetail) {
console.log('User userloginstatus ');
console.log(userloginstatus);
console.log('User details ');
console.log(userdetail);
//User detail is the json object of the facebook user.you can use that information as per your need
});
}
</script>
<body>
<div id="fb-root"></div>
<input type="button" id="fb-login" value="Facebook login"/>
</body>
</html>